How do I make the K key look up documentation in a language-specific tool instead of man pages?
Answer
:set keywordprg
Explanation
The K key in normal mode looks up the word under the cursor using the program defined by keywordprg. By default this is man, but you can point it at any documentation tool — or even an Ex command — to get context-relevant help without leaving Vim.
How it works
:set keywordprg=man " default: look up in man pages
:set keywordprg=python3\ -m\ pydoc " Python docs via pydoc
:set keywordprg=ri " Ruby docs via ri
:set keywordprg=:help " Use Vim's own :help (note the : prefix)
When keywordprg starts with :, Vim treats it as an Ex command, appending the keyword as an argument. This means :set keywordprg=:help makes K run :help word — perfect when editing Vimscript.
Example
For a Vimscript development workflow, set this globally or via an ftplugin:
" In ~/.vim/ftplugin/vim.vim or ~/.config/nvim/ftplugin/vim.lua:
setlocal keywordprg=:help
Now pressing K over setline opens :help setline(), over BufReadPost opens :help BufReadPost, and so on — with no typing required.
Tips
- Use
setlocalin ftplugin files to set this per filetype without affecting other buffers - In Neovim, LSP plugins typically override
keywordprgwithhover()onLspAttach— check:verbose set keywordprg?to see the current value and where it was set - Pass multiple words by combining with a shell script if the tool supports it
:set keywordprg=:Manworks with Neovim's built-in:Mancommand for section-aware man page display