How do I fix the indentation of an entire file in Vi?

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 up. I want to fix this in one fell swoop.


= , the indent command can take motions. So, gg to get the start of the file, = to indent, G to the end of the file, gg=G .


Before pasting into the terminal, try :set paste (and then :set nopaste after you're done). This will turn off the auto-indent, line-wrap, etc. features that are messing up your paste.

edit: Also, I should point out that a much better result than = indenting can usually be obtained by using an external program. For example, I run :%!perltidy all the time. astyle, cindent, etc. can also be used. And, of course, you can map those to a key stroke — and map different ones to the same keystroke depending on file type


如果你想重新加入你所在的区块而不必输入任何和弦,你可以这样做:

[[=]]
链接地址: http://www.djcxy.com/p/4898.html

上一篇: Vim删除空行

下一篇: 如何修复Vi中整个文件的缩进?