Some handy vim key mappings

October 5th, 2006 by Strawp

This has just saved me a whole load of keystrokes on some very dull HTML marking up of content pasted into vim from a Word document. I’ll post it here in case anyone else finds it useful:

:map <F2> 0i<p><CR> <Esc>$a<CR></p><Esc>
:map <F3> 0i <li><Esc>$a</li><Esc>
:map <F4> 0i<ul><CR><Esc>
:map <F5> $a<CR></ul><Esc>
:map <F6> 0i<CR><h4><Esc>$a</h4><Esc>
:map <F7> 0i<ol><CR><Esc>
:map <F8> $a<CR></ol><Esc>
:map <F9> 0i<blockquote><CR> <Esc>$a<CR></blockquote><Esc>
:map <F11> bi<strong><Esc>ea</strong><Esc>
:map <F12> :%s/^• \(.*\)$/ <li>\1<\/li>/ge<CR>:%s/^[0-9]\+\. \(.*\)$/ <li>\1<\/li>/ge<CR>:%s/…/\.\.\./ge<CR>

Either run each one of these commands or paste the whole lot into the end of your vimrc file. This will map all the F-keys as follows:

F2 – Wrap line in paragraph tags
F3 – Wrap line in list item tags
F4 – insert unordered list tag before current line
F5 – Insert unordered list close tag after current line
F6 – Insert a new line, then wrap current line in header 4 tags
F7 – Insert ordered list tag before current line
F8 – Insert ordered list close tag after current line
F9 – Wrap current line in blockquotes and indent
F11 – Wrap current word in strong tags
F12 – Perform the following substitutions:
– bullet points into list items
– numbered lists into list items
– Word elipsis character into 3 full stops

Have some useful links on vim to go with that:
And my bookmarks tagged vi

Comments are closed.