Lets say I have the following cmake file (with | being the cursor).

add_exe|cutable(myapp main.cpp)

Now if I go to terminal and consult cmake documentation with cmake --help add_executable I get a really nice help message.

I want to bring that help message to vim preview window (or something similar) much like how :help keyword works in vim.

Is that possible?

  • Run a :term in vim 8 and above, or use the Clam plugin. Will flesh out answer later – D. Ben Knoble Jul 28 '18 at 14:46
  • @D.BenKnoble You Rock! Clam is awesome, all i needed to do was(autocmd Filetype cmake nnoremap K :Clam cmake --help <cword><cr>:set filetype=cmake<cr>gg) – amin Jul 28 '18 at 15:17
  • 1
    see my answer for a breakdown of your options – D. Ben Knoble Jul 29 '18 at 14:33

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 vim or nvim you're using, or on external code.

:read !

The :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.

End result: :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 :term ++noclose
  • 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
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.