Friday, November 30, 2007


It's often handy to shift blocks of text left and right, and Vim makes it easy. I like to set shiftwidth=1 in my vimrc file so I can have nice fine-grained control over my shifts. First you should define the following snippit (stolen from Vim Tips) in your vimrc:

vnoremap < <gv
vnoremap > >gv

Now highlight a column of text using blockwise visual selection (ctrl-v on Unix platforms, ctrl-q on Windows) and then hit > or <

>>>> (would shift four shiftwidths to the right)

You can also use traditional ex mode to accomplish the same. Go to the first column of a given block and type ma (in normal mode) to set mark a. Go the the end of the block you want to indent, first column, and set mark b by typing mb (in normal mode). Now issue the following ex-command.

:'a, 'b>> (shift two columns to the right)


Anonymous said...

I most often just use a count with the >> command:

(indents 5 lines)


Anonymous said...

This is a very old post but in case someone comes:

Without doing any configuration you can obtain the same results by pressing '.' (dot).

For example: