How do I look up documentation for the keyword under the cursor?
Answer
K
Explanation
Pressing K in normal mode runs a lookup program on the word under the cursor. By default it opens the man page, but you can customize keywordprg to use any documentation tool. This is a powerful way to get instant help on functions, commands, or keywords without leaving Vim.
How it works
Ktakes the word under the cursor and passes it to the program set inkeywordprg- By default,
keywordprgis set toman, soKonprintfopensman printf - In Vim help files,
Kopens:helpfor the keyword instead {count}Kpasses the count as the man section number (e.g.,3Konprintfopensman 3 printf)
Example
With the cursor on strftime in a C file:
char *result = strftime(buffer, sizeof(buffer), "%Y-%m-%d", tm);
^cursor here
Pressing K opens man strftime showing the full documentation.
Tips
- For Python files:
:setlocal keywordprg=python3\ -m\ pydocto look up Python docs withK - For Vim files:
keywordprgis automatically set to:help - For Ruby:
:setlocal keywordprg=rito use Ruby's documentation tool - Use
visual Kto look up the visually selected text instead of just the word - Set
keywordprgper filetype in~/.vim/after/ftplugin/for language-specific docs