VIM: store output of external command into a register

Viewed 5369

Is it possible to run an external command and store its output in a register?

  • :redir works for ex commands, not for external commands (afaik)
  • :r ! runs the external command but directly inserts output into the current buffer
2 Answers

:redir does seem to work, though a little clunky. If you're looking to pipe data from your file into the external command it may be easier.

:redir @a
:w ! ls -1
:redir END
"ap

EDIT: Interestingly, I just noted that it seems to be working for me in neovim v0.4.3 but not in vim 8.2.100 (MacOS 10.15.2, both installed via homebrew).

Related