Tip 1127 Printable Monobook Previous Next
created February 10, 2006 · complexity basic · author Marc Weber · version 5.7
" A little nice idea I got today... " " I've noticed that I often use one session mappings .. Sometimes :bn " sometimes :make specialtarget " in each case I need it often. " vim supports this by @: but there are cases when I want to press one key only " and other cases I want to user other commands as well. " Having to type :map <F5> :<cmd><CR> does need some time and I'm lazy ;-) " So just copy this text, put it into .vim/plugins/mapFromF1ToF12.vim and enjoy " Try " :echo "dummy"<CR> " <F5> " now you can use F5 to execute :echo "dummy" " Perhaps you want to have mappings local to your buffer only. " Then use map <buffer> and unmap <buffer> instead function MapLastCommandToKeys(keysToMapTo) exe "unmap ".a:keysToMapTo exe "map ".a:keysToMapTo." :".histget("cmd")."<CR>" endfunction function PrepareMap(keysToMapTo) exe "map ".a:keysToMapTo." :call MapLastCommandToKeys('".a:keysToMapTo."')<CR>" endfunction " This will allow you to use F1 PrepareMap('<F1>') " This while loop will allow you to use F2,F3,..,F12 let i=2 while i<13 call PrepareMap('<F'.i.'>') let i=i+1 endwhile " of cause you can use any mapping eg \a: PrepareMap("\a")
Recordings can do much more (encompassing other modes) than handle :cmd-line executions. They can also be repeated. See :help complex-repeat.
From normal mode,
- To record to register a: 'qa'
- Perform any keystrokes and :cmd-line executions.
- To stop recording: 'q'
- To perform recording 2 times: '2@a'
- To perform recording 55 more times: '55@@'
Community content is available under CC-BY-SA unless otherwise noted.