Is it possible to indent blocks of code in vim instead of going to each line and indenting a line at a time?
Maybe highlight the code and execute a command that will indent the highlighted code?
Is it possible to indent blocks of code in vim instead of going to each line and indenting a line at a time?
Maybe highlight the code and execute a command that will indent the highlighted code?
First, for indenting there's both the >
command, which simply shifts to the right by adding one level of indent (how much is determined by the 'shiftwidth'
option, and 'expandtab'
tells whether to use Tabs or spaces), and the =
command, which applies (language-specific) indentation rules.
Both commands work on line(s) when doubling, i.e. >>
/ ==
; you address multiple lines by prepending a number.
But they also take a {motion}
, e.g. 3j
(3 lines down), or }
(to the end of the paragraph).
And finally, you can make a visual selection (V
), make it the right size, and then apply the command to it.