I am working with a CMS where the code’s indentation is a mess. Is it possible to fix it automatically with vim, running some command?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Generally you can use the
=operation to indent.See
:help =(You’ll also need to have
filetype indent onin your vimrc to enable different indentation rules for each type of file you’ll edit)gg=Gwill reindent a whole file. (gg move to beginning of the file, = will reindent every line under motion, G goes to the end of the file)By default, Vim support well C and C like language. See
:help C-indentingfor options. You’ll probably need to adjust these options before reformating your files. You’ll have to defineset cindentin your .vimrc if you want to use the “smart” indentations that is controlled bycinoptions.See
:help indent-expressionfor other languages.In addition, you’ll probably will have to fiddle with
shiftwidth,expandtabandtabstopoptions if you want to use whitespaces or tab to indent.For example, if you to replace all tab by 4 spaces, you ‘ll have to use: