How can I indent multiple lines, and indent "backwards", in gvim?

I'm just learning vim (via gvim, I used to be a Notepad++ user) and haven't yet found how to do 2 things:

  1. 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.
  2. Also, is there a way to move backwards equivalent to "Shift+Tab" in Notepad++?

Thanks

1

3 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<)

4

What 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.

4

The preferred approach is to let vim perform auto-indentation. Don't forget this in your .vimrc:

set ai
filetype indent on

Then, 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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like