What Is Vim (It's Easier than You Think)
Subject:   More vim stuff
Date:   2006-07-11 19:07:34
From:   MSchienle
I've been using vi[m] for longer than I care to admit. While the article was mostly a rehash for me, I really appreciate the macro coverage in the followup. For some reason, I've never quite been able to keep that straight in my mind. I'll give it another go.

Here are a few items I use on a regular basis for [un]commenting and [un]indenting blocks of lines, and a bunch of other common tasks. I typically mark the start of a block as "a" and the end of the block as "b". So, some of these maps depend on that setting. The ctrl-m at the end of some lines forces a newline. That gets entered as ctrl-v, ctrl-m.

" backslash less than - remove first pound-tab
map \< :'a,'bs/# //^M
" backslash greater than - insert pound-tab at beginning
map \> :'a,'bs/^/# /^M
" backslash left bracket - remove first tab
map \[ :'a,'bs/^ //^M
" backslash right bracket - insert tab at beginning
map \] :'a,'bs/^/ /^M

" backslash d - adds in a history comment line with date
map \d o# Modified: Mike Schienle^M^[!!date '+\%D'^MkJo#

" writes out the marked text to a tmp file
" calls an external perl program to format it
" reads in the updated tmp file
" backslash = - align selection on = signs
map \= :'a,'bw! ~/tmp/equals.tmp^M:'a,'bd^MO^[!! ~/tmp/equals.tmp^M

I have three pages of these tacked up in my office for various things.