Indenting a bunch of lines in Vim

六月ゝ 毕业季﹏ 提交于 2019-11-30 12:15:21

问题


Is there a way to indent a selection of lines in Vim, like we have in text editors where we select a bunch of lines and press tab (or shift tab) to indent/unindent the selected lines?

I am talking about general indentation and not related to code indentation.


回答1:


Use visual mode as Peter suggests. You can also use X>> where X is the number of lines you want to indent. E.g. 5>> indents five lines from current line and down.




回答2:


You can select a set of lines with visual line mode (via Shift + V), and then type

>

and, to dedent,

<

You can also add numeric arguments. Find out you didn't indent enough? Hit gv to re-select your previous selection.

While typing in normal mode, try out Ctrl + T or Ctrl + D to indent or dedent.




回答3:


I use the following mappings to indent/unindent:

vmap <TAB> >gv
vmap <S-TAB> <gv

Use TAB to indent and shift-TAB to unindent the visually selected lines.

If a block is selected Vim indents/unindents what is right of the start of the block.




回答4:


There's a Vim Cast on this topic: Indentation commands

I like Vim Casts. They are informative and pleasant to watch.




回答5:


As suggested by the other answers you can use >. Alternatively, you can automatically correctly indent your code by selecting the set of line in visual mode (using shift+V), and then using =, or using == to indent the current line.



来源:https://stackoverflow.com/questions/2332340/indenting-a-bunch-of-lines-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!