In many GUIs when I select a section of text and then hit the Tab or Shift+Tab button the selected section will indent in or out.
In VIM I can select a visual section and then hit the < or > key to change indenting, however once I hit the < key my selection is cleared so I am stuck selecting the section again and hitting < again. This gets really annoying when I am trying to indent something a few stops in and want visual feedback.
Is there anyway to indent stuff in and out in vim while keeping the current selected text selected?
Is there a trick to re-map Tab and Shift+Tab so they behave in this way in visual mode?
Using Command “>”: You need to open the visual block mode first for indentation, using the “ctrl+v” shortcut. After that, press the “next” button to select the number of characters to be indented and press “j” to cover the lines to tab along, i.e., 2 to 4.
Put the cursor anywhere in the first line. Press V then jj to visually select the three lines. Press > to indent (shift text one ' shiftwidth ' to the right), or press < to shift left. Press . to repeat the indent, or u to undo if you have shifted too far.
You can prefix a number, ie. 2>
to indent two tab stops. Or, you can use >
to indent once, then .
to indent again (this works even though the block is no longer highlighted). If you go too far, u
will undo one step at a time.
Another useful command is gv
to restore the last visual block if you need to apply a different command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With