Using only vanilla Vim and complementary to
'keywordprg' (defaults to
man) on the word under the cursor (in normal mode) or the current selection (in visual mode) and displays the output. As recommended in another answer, this can be used to refer to the documentation for standard functions and variables (some IDEs might blur the line between documentation for standard and non-standard libraries, you will certainly not get the latter from
However, as missed by that answer, pressing
printf will output the documentation of
printf(1) ("the command
printf(3) ("the function
printf" from the C Standard Library) which you are probably after. See What do the numbers in a man page mean? for more details about this distinction. Practically speaking, it is the output of
man [-s] 1 printf (to which
man printf defaults) instead of
man [-s] 3 printf.
As stated in its documentation (
K takes a count:
'keywordprg' 'kp' string (default "man" or "man -s")
Program to use for the |K| command.
When "man", "man -s" or an Ex command is used, Vim will automatically
translate a count for the "K" command and pass it as the first
argument. For "man -s" the "-s" is removed when there is no count.
Therefore, you can get the documentation for
As this is likely to be the desired behaviour every time
K is used, I see 2 options:
and, as this behaviour is only useful in C code, add your choice among the solutions above to a
ftplugin in your
after-directory (e.g. to
~/.vim/after/ftplugin/c.vim). Also note that, according to @muru's comment, the packages containing the manpages might have to be installed beforehand.
Finally, as mentioned by @kyticka, for C++ (although also helpful in C), you may use a similar approach by replacing
cppman as your
'kp' e.g. in
cppman can be used to cache entries from cplusplus.com as (offline)
man pages and
man can be set up to read those pages, allowing you to use the default to access documentation for the C++ Standard Library from
man and, by extension, from the default