Getting terminal output into vim
We have several options to do this, which I will describe below. Note that some may depend on the version of
nvim you're using, or on external code.
:read command (
:r) is typically used to read in files to the current buffer. This has let users create many wonderful templating systems, among other uses.
However, in typical Unix style, external command output can we treated like a file.
:read !cmake --help <cword> will put the output in your current buffer. You could create a function to put it in a new window, if you like.
Built-in terminal support was developed in vim 8 (though I think it only stabilized in 8.1).
We can either:
- open a terminal and run the command separately, in which case we might want to use
- or tell vim to run exactly the command we want
I'll show the latter:
:term cmake --help <cword>
This should put the output in a terminal buffer (no longer running), much like a preview window.
I started using clam before vim got terminal support. It's a nifty little plugin that basically implements the 'read command output into a new window' piece I described above, with a couple of bonus mappings for manipulating it.
Install it, and, as the OP mentioned in comments, set up a mapping.
I would place the following code in
~/.vim/after/ftplugin/cmake.vim, to take advantage of the filetype mechanism and not clutter my
vimrc with autocommands.
nnoremap K :Clam cmake --help <cword><cr>
The original from the comment was
autocmd Filetype cmake nnoremap K :Clam cmake --help <cword><cr>:set filetype=cmake<cr>gg