Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabbing visual selection

Tags:

vim

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?

like image 507
Sam Saffron Avatar asked Jan 14 '09 08:01

Sam Saffron


People also ask

How do you add a tab to selected text in Vim?

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.

How do I indent selected text in Vim?

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.


1 Answers

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.

like image 93
Greg Hewgill Avatar answered Sep 27 '22 20:09

Greg Hewgill