Showing posts with label shift. Show all posts
Showing posts with label shift. Show all posts

Thursday, November 19, 2009

Shift-Tab'ing

I have the following in my vimrc:

set sts=4
set et

This allows me to take advantage of the convenience of the tab key when editing while actually inserting spaces into the current buffer. Intuitively I've always wished I could shift-tab to unindent the current line one tab stop. After a minute of fiddling with my vimrc, I found a solution.

imap <S-Tab> <C-o><<

I should also mention that << and >> shifts the provided text based on your shiftwidth setting.

Friday, November 30, 2007

Shifting

It's often handy to shift blocks of text left and right, and Vim makes it easy. I like to set shiftwidth=1 in my vimrc file so I can have nice fine-grained control over my shifts. First you should define the following snippit (stolen from Vim Tips) in your vimrc:

vnoremap < <gv
vnoremap > >gv

Now highlight a column of text using blockwise visual selection (ctrl-v on Unix platforms, ctrl-q on Windows) and then hit > or <

>>>> (would shift four shiftwidths to the right)

You can also use traditional ex mode to accomplish the same. Go to the first column of a given block and type ma (in normal mode) to set mark a. Go the the end of the block you want to indent, first column, and set mark b by typing mb (in normal mode). Now issue the following ex-command.

:'a, 'b>> (shift two columns to the right)