Reputation: 167
This question may be a little off topic. But I was wondering if there was a way for me to look at the descriptions of C
functions using vim
or neovim
. Is it possible to look at their documentations by doing something like :help
? This would really be helpful since I wouldn't need to lookup to my browser everytime.
I am unclear about these things:
:help
be my friend here ?Neovim
inside Ubunutu 20.04
in WSL
. Is this helpful somehow ?Upvotes: 1
Views: 1733
Reputation: 8982
The previous answer recommending cppman
is the way to go. There is no need to install a bulky language server just for the purpose of having the hover
functionality. However, make sure you're caching the man pages via cppman -c
. Otherwise, there will be a noticeable delay since cppman
is fetching the page from cppreference.com on the fly.
If you like popups for displaying documentation, convert the uncompressed man pages (groff -t -e -mandoc -Tascii <man-page> | col -bx
), and set keywordprg
to your own wrapper to search for keywords according to your needs.
Upvotes: 1
Reputation: 15186
Let's explain how "K" command works in more detail.
:!
command. So running man
tool is as easy as:!man <C-R><C-W>
Here <C-R><C-W>
is a special key combination used to put word under cursor from text buffer down to command line.
Same for showing Vim's built-in help page
:help <C-R><C-W>
So doing set keywordprg=man
(default for *nix systems) makes K to invoke !man
tool; while set keywordprg=:help
is for bultin help.
Also, the option :h 'keywordprg'
is made global or local-to-buffer, so any Vim buffer is able to overwrite global setting. For example, this is already done by standard runtime for "vim" and "help" buffers, so they call ":help" instead of "man".
:!man
command is that it shows "black console". It'd be nice if we could capture man's output and open it inside Vim just like a builtin help page. Then we could also apply some pretty highlighting, assign key macros and all such. This is a pretty common trick and it is already done by a standard plugin shipped with Vim/Neovim.A command that the plugin provides is called :Man
, so you can open :Man man
instead of :!man man
, for example. The plugin is preactivated in Neovim; for Vim you still need to source one file manually. So to make use of this plugin you'll need something like this
set keywordprg=:Man
if !has("nvim")
source $VIMRUNTIME/ftplugin/man.vim
endif
Upvotes: 0
Reputation: 70333
By pressing K
, the keyword under the cursor is looked up using a configured keyword lookup program, the default being man
. This works pretty much out of the box for the C standard library.
For C++, you might want to look at something like cppman.
Upvotes: 5
Reputation: 1299
Well yes, you can get the description of C
functions by using a LSP (language server plugin)! Here is an image of me using clangd
as my LSP:
You'd "just" need to install the LSP and start it. I don't know how familiar you're with neovim, but just in case if you don't know how to install a plugin or to be more specifique: If you don't know how you can install a LSP server, then you can do the following:
But yeah, that's it. If you have any further questions feel free to ask them in the comments.
Happy vimming c(^-^)c
Upvotes: 1