I'm just learning vim (via gvim, I used to be a Notepad++ user) and haven't yet found how to do 2 things:
- How can I indent a set of rows x spaces/tabs right? In Notepad++, for example, I just highlight the rows I need and press 'Tab' key.
- Also, is there a way to move backwards equivalent to "Shift+Tab" in Notepad++?
Thanks
13 Answers
Start at the first line you want to indent, then press > and type the number of lines you want to indent and press > again (for 10 lines you'd press >10>) To un-indent you'd just use < instead of > (<10<)
4What you want are the > and < commands, see ":help shift-left-right".
You can use these commands in multiple ways, but since you specifically mentioned highlighting, you can just use your mouse or keyboard to highlight the lines you want to shift/unshift and press > or <.
Instead of using visual mode (highlight) you can provide a count and >> or <<. For example, 3>> will indent the current line and two lines below it.
The preferred approach is to let vim perform auto-indentation. Don't forget this in your .vimrc:
set ai
filetype indent onThen, if you open a file badly indented, you can then use the = command (in conjunction with a motion, e.g. gg=G to reindent the whole file, == to reindent the current line, =i{ to reindent the current {} block, etc.).
>> and << exist indeed, since the old and plain vi, but they are really cumbersome for real and long term editing.