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

前端 未结 16 2218
不知归路
不知归路 2020-12-02 03:24

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

16条回答
  •  离开以前
    2020-12-02 04:01

    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 and other 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.

提交回复
热议问题