In Vim, how can I shift a block of code to right?

In command mode, you can use >> to indent a single line. 4>> will indent the current and next three lines.

If you don’t know how many lines in advance (it may be quite large), you can use ranges. Go to the first line of the range and enter ma to place marker A. Then go to the last line and enter >'a to indent from here to marker A. You can do all sorts of wonderful things with ranges.

How they’re indented depends on a couple of things like your shiftwidth settings. I always have my shiftwidth and tabstop settings the same to avoid problems:

:set ts=4 sw=4

(for example).

Leave a Comment