Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim indenting a block of code inward and outward

Tags:

vim

macvim

I am using mvim . I am trying to map keys so that I could visually select elements then I could indent the code inward or outward. However while doing outward work after every keystroke one more line at the bottom get selected. What is the fix.

" Ctrl-x - move the block of visually selected code one tab right and keep visual mode alive
" Ctrl-z moves the data in opposite direction
" Usage : shift v and select multiple lines. then Ctrl x multiple times and
" then Ctrl z multiple times
vmap <C-x> >gv  
vmap <C-z> <gv  
like image 299
Nick Vanderbilt Avatar asked Mar 02 '10 20:03

Nick Vanderbilt


1 Answers

Why would you go to the trouble when you already can do this?

>> - increase indent of selected block

<< - decrease indent of selected block

This will cause you to lose the focus. If you want to continue indenting just type . to repeat the last action. You can also type gv to re-select your last selection.

Another option is to select and type a number before indenting, which is the same as repeating the >> or << as many times as the number you typed.

like image 178
Nathan Fellman Avatar answered Sep 17 '22 13:09

Nathan Fellman