Quick notes:
– imap is for when you are in insert mode
– map is when your are in command mode
Thus when you are in the insert mode, sometime you need to exit to the command mode first using the esc key.
The i is for going back to the inser mode. The cr key is the Enter key.
The script below will make vim to:
– Find and Replace when I hit F3
– Undo when I hit F9
– Saves when I hit F10
– Quit when I hit F12
– Prints a debugging statement for PHP when I press F8
– Also disables the REPLACE mode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | """""""""""""""""""""""""""""""""""""" " Quick commands using F keys """"""""""""""""""""""""""""""""""""""" :imap <F3> <esc>:%s/search/replace/gc :map <F3> :%s/search/replace/gc :imap <F9> <esc>:u<cr>i :map <F9> :u<cr>i :imap <F10> <esc>:w!<cr>i :map <F10> :w!<cr>i :imap <F12> <esc>:q!<cr> :map <F12> :q!<cr> :imap <F8> error_log("\n".__FILE__ . ' ['. __LINE__. '] ' . __CLASS__.'::'.__FUNCTION__.'() D>'. print_r(, true));<cr> :map <F8> ierror_log("\n".__FILE__ . ' ['. __LINE__. '] ' . __CLASS__.'::'.__FUNCTION__.'() D>'. print_r(, true));<cr> """"""""""""""""""""""""""""""""""""""" " Disable REPLACE mode """"""""""""""""""""""""""""""""""""""" function s:ForbidReplace() if v:insertmode isnot# 'i' call feedkeys("\<Insert>", "n") endif endfunction augroup ForbidReplaceMode autocmd! autocmd InsertEnter * call s:ForbidReplace() autocmd InsertChange * call s:ForbidReplace() augroup END |