created 2005 · complexity basic · author Max Ischenko · version 5.7
It can be really annoying when you keep hitting the F1 key accidentally, and the Help screen pops up. Here is a solution:
:nmap <F1> :echo<CR> :imap <F1> <C-o>:echo<CR>
You can't just ":unmap <F1>" because Vim would complain that no such mapping exists.
You could still access the help system via
:help command or the gvim menu.
This maps F1 to 'no operation' (do nothing):
:nmap <F1> <nop>
and this maps F1 to Escape:
map <F1> <Esc> imap <F1> <Esc>
I use the following. Now both F1 and Esc get me out of insert mode, but I can still use F1 to start (and quit) help in other modes.
inoremap <F1> <Esc> noremap <F1> :call MapF1()<CR> function! MapF1() if &buftype == "help" exec 'quit' else exec 'help' endif endfunction
Excellent idea. As I mostly call help on a specific topic, I propose a definition going even further:
function SophHelp() if &buftype=="help" && match( strpart( getline("."), col(".")-1,1), "\\S")<0 bw else try exec "help ".expand("<cWORD>") catch /:E149:\|:E661:/ " E149 no help for <subject> " E661 no <language> help for <subject> exec "help ".expand("<cword>") endtry endif endfunc nnoremap <silent> <F1> :call SophHelp()<CR> imap <F1> <Esc><F1>
F1 is really annoying but sadly nothing of all these worked for me. I use ubuntu and still when I press F1 it brings up the GNOME terminal manual window!!! Any thoughts?
- If it brings up Gnome help and not Vim help, it means your Gnome window manager snatches it before Vim has a chance to see it. The solution, if any, is somewhere in your Gnome (and/or WM and/or Compiz and/or ...) settings. — Tonymec 17:37, April 9, 2010 (UTC)
- Ok Τonymec thank you very much. Finally what I did to fix it is the following. First of all with xev utility I found out that the keycode of F1 is 67. Then I issued the command xmodmap -e "keycode 67 = Escape". That was it. F1 behaves like Escape now
- I disable the help shortcut in the gnome terminal preferences Edit > Keyboard Shortcuts > Help — dcb Feb 17 2011
nnoremap <F1> <Esc>g<C-G>