In Vim, what is the command to correct the indentation of all the lines?
Often times I\'ll copy and paste code into a remote terminal and have the whole thing messed
You can use tidy application/utility to indent HTML & XML files and it works pretty well in indenting those files.
Prettify an XML file
:!tidy -mi -xml %
Prettify an HTML file
:!tidy -mi -html %
if you do not want to use :set paste
, middle-click, set nopaste
, you can also paste the content of the clipboard:
"*p
"+p
That way you don't have to leave normal mode.
if you have to paste +
or *
depends on how you selected the text, see :help quoteplus
.
vim-autoformat formats your source files using external programs specific for your language, e.g. the "rbeautify" gem for Ruby files, "js-beautify" npm package for JavaScript.
In Vim, use :insert
. This will keep all your formatting and not do autoindenting. For more information help :insert
.
If you want to reindent the block you're in without having to type any chords, you can do:
[[=]]
For complex C++ files vim does not always get the formatting right when using vim's =
filter command. So for a such situations it is better to use an external C++ formatter like astyle (or uncrustify) e.g.:
:%!astyle
Vim's '=' function uses its internal formatter by default (which doesn't always gets things right) but one can also set it use an external formatter, like astyle, by setting it up appropriately as discussed in this question.