Friday, 19 March 2010
VIM: Creating a Custom Command with a Temporary Map
Maps allow us to create our custom Vim commands
The VIm initialization file .vimrc is typically used to store maps.
eg:-
imap ,,, <esc>bdwa<<esc>pa><cr></<esc>pa><esc>kA
" s commands these are wrap html around visually selected text
vnoremap sb "zdi<b><C-R>z</b><ESC>
vnoremap sq "zdi"<C-R>z"<ESC>
vnoremap sp "zdi<p><C-R>z</p><ESC>
vnoremap s( "zdi(<C-R>z)<ESC>
However it is very easy to create a temporary map eg to use the key '#' as a map
eg a map to copy the word under the cursor into the paste buffer
:map # "*yiw
A map has an advantage over a recording in this case as it is only necessary to type one character, a recording has an advantage over a map in that you don't have to think it out, so why not combine the two?
Map the key # such that it executes the recording q
:map # @q
The VIm initialization file .vimrc is typically used to store maps.
eg:-
imap ,,, <esc>bdwa<<esc>pa><cr></<esc>pa><esc>kA
" s commands these are wrap html around visually selected text
vnoremap sb "zdi<b><C-R>z</b><ESC>
vnoremap sq "zdi"<C-R>z"<ESC>
vnoremap sp "zdi<p><C-R>z</p><ESC>
vnoremap s( "zdi(<C-R>z)<ESC>
However it is very easy to create a temporary map eg to use the key '#' as a map
eg a map to copy the word under the cursor into the paste buffer
:map # "*yiw
A map has an advantage over a recording in this case as it is only necessary to type one character, a recording has an advantage over a map in that you don't have to think it out, so why not combine the two?
Map the key # such that it executes the recording q
:map # @q
Comments:
<< Home
Very nice!
I've just started working with macros, and '@q' definitely wasn't rolling off the finger-tips (the easiest combo seemed to be @t... pinky on th the @, index on 't').
I've just started working with macros, and '@q' definitely wasn't rolling off the finger-tips (the easiest combo seemed to be @t... pinky on th the @, index on 't').
Subscribe to Post Comments [Atom]
<< Home
Subscribe to Posts [Atom]
Post a Comment