Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to indent a selection in gVim (Win32)

I'd like to indent a block of text.

I am able to do this in the Linux build of gVim.

I do this in the state of gVim where I'm not in the insert or visual mode. The bar at the bottom is blank on the left, and the line number and percentage are showing on the right hand side.

Then I perform the following procedure: I select a block of text via click and drag. Then I hit Shift + .. After that, I hit Esc and the block of text will move over a tab.

If I do this in Windows however, it just replaces the block with >.

I am just running the stock Windows rc file and version 7.1 of gVim.

like image 514
Fredrick Avatar asked Nov 25 '08 21:11

Fredrick


People also ask

How do I indent a selection in Vim?

Press V then move the cursor to select a range of lines, then press = to indent the selection.

How do I tab multiple lines in Vim?

To tab or add the indentation at multiple lines, try “shift+dot” i.e., “.” Shortcut once. You will see it will add an indentation of one character at each selected line from the start. If you want to add indentation without stopping, then you have to try the “.” Key from the keyword after using “shift+.”.

How do I indent multiple times in Vim?

Select what you want (typically with v or Shift + v ) then type 5> . If you need to fix or repeat the same selection, use gv . Show activity on this post. You can select the current line by pressing v , and then type 5> to indent the current line 5 times, the equivalent of pressing > 10 times.


2 Answers

If you first enter SHIFT-V, and than shift+arrows to select the text, it will indent. You can also use SHIFT-V, and use 'hjkl' to select the block.

If you use shift+arrows or the mouse to select a block of text, it does not work and the selection will be replaced with a '>'. This can be changed when you change selectmode;

set selectmode=mouse,key

  • default setting after behave mswin

set selectmode=key

  • now you can select with the mouse and press '>' to indent

set selectmode=

  • now you can select both with the mouse and shifted arrow keys and press '>' to indent

If you add this to your vimrc, do it after behave mswin

like image 110
wimh Avatar answered Sep 21 '22 21:09

wimh


Related to this, I use a handy remap for visual mode that allows indenting the text multiple times while keeping your text selected. Similar to how visual studio lets you select and hit tab (or shift-tab) to indent.

Add the following to your .vimrc

" Pressing < or > will let you indent/unident selected lines
vnoremap < <gv
vnoremap > >gv

Also you can use == to have vim try and determine the correct indenting automatically. It will work on any line buy just placing the cursor there and pressing == or you can do fancy stuff like select the entire file and press == to fix all the indenting (works wonders on html generated by wysiwyg editors).

like image 40
csexton Avatar answered Sep 21 '22 21:09

csexton