Disable F1 built-in help key
From Vim Tips Wiki
Tip 1007 Previous Next Created: October 1, 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.
[edit] Comments
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:/
exec "help ".expand("<cword>")
endtry
endif
endfunc
nnoremap <silent> <F1> :call SophHelp()<CR>
imap <F1> <Esc><F1>
