How do I make the K key look up words in Vim's own help instead of the man page?
Answer
:set keywordprg=:help
Explanation
By default, pressing K in Normal mode runs the word under the cursor through an external program — usually man. For Vimscript or Vim option names, this is useless. Setting keywordprg=:help redirects K to Vim's own :help system, so you can instantly look up any Vim keyword by placing the cursor on it and pressing K.
How it works
keywordprgdefines the program (or Ex command) invoked byK- When the value starts with
:, Vim treats it as an Ex command and appends the word under the cursor as the argument :set keywordprg=:helpis therefore equivalent to running:help {word}on demand- This setting is buffer-local with
:setlocal, so you can scope it to specific filetypes
Example
Add to your vimrc for all files, or use an autocmd for Vimscript files specifically:
" Global: K always looks up Vim help
set keywordprg=:help
" Or: only for .vim files
autocmd FileType vim setlocal keywordprg=:help
" For Python files, use pydoc instead
autocmd FileType python setlocal keywordprg=pydoc3
With the cursor on the word autocmd, press K to immediately open :help autocmd.
Tips
- The default value is
manon Unix and:helpon Windows for Vim help files - You can set it per-filetype:
manfor C,pydoc3for Python,:helpfor Vimscript Kalso works in Visual mode — it will look up the selected text- Use
:set keywordprg?to inspect the current value for the active buffer