17

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Fredrick
  • 1,000
  • 2
  • 13
  • 22

5 Answers5

21

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

wimh
  • 14,481
  • 5
  • 42
  • 89
  • If I esc out of modes, hit shift + v, release the v but continue to hold shift I am able to use the mouse to select to some extent. Thanks! – Fredrick Nov 26 '08 at 15:13
  • I also had to add `set keymodel=startsel,stopsel` to make it work as expected. – Florian Nov 26 '15 at 07:57
5

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).

csexton
  • 21,619
  • 15
  • 51
  • 53
  • Good one, but I just use "." (dot) to indent previously indented lines: Vjj>. (repeat dots as necessary) – zbstof Apr 26 '12 at 12:00
3

Esc -> Shift+V -> Select Lines -> > >

Sagar Jain
  • 6,261
  • 10
  • 40
  • 73
EBGreen
  • 33,707
  • 11
  • 58
  • 80
1

You need to change behave mswin to behave xterm in your vimrc file.

Jeremy Bourque
  • 3,383
  • 1
  • 19
  • 18
  • I like some of the mswin behavior though. It seems like I should be alternative shortcut or a way to configure a shortcut to do the same thing. – Fredrick Nov 26 '08 at 00:12
  • It looks like the answer you're looking for was provided by Wimmel in his explanation of the selectmode setting. – Jeremy Bourque Nov 26 '08 at 15:12
1

You can use text objects if you want to avoid visual mode entirely. For example >ap in Normal mode indents one paragraph, >aB indents one curly-brace block, etc. See :h text-objects.

Brian Carper
  • 66,618
  • 25
  • 158
  • 164