vimtricks.wiki Concise Vim tricks, one at a time.

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

  • keywordprg defines the program (or Ex command) invoked by K
  • When the value starts with :, Vim treats it as an Ex command and appends the word under the cursor as the argument
  • :set keywordprg=:help is 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 man on Unix and :help on Windows for Vim help files
  • You can set it per-filetype: man for C, pydoc3 for Python, :help for Vimscript
  • K also works in Visual mode — it will look up the selected text
  • Use :set keywordprg? to inspect the current value for the active buffer

Next

How do I insert the entire current line into the command line without typing it?