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

前端 未结 16 2235
不知归路
不知归路 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

    The master of all commands is

    gg=G

    This indents the entire file!

    And below are some of the simple and elegant commands used to indent lines quickly in Vim or gVim.

    To indent the all the lines below the current line

    =G
    

    To indent the current line

    ==
    

    To indent n lines below the current line

    n==
    

    For example, to indent 4 lines below the current line

    4==
    

    To indent a block of code, go to one of the braces and use command

    =%
    

提交回复
热议问题