Is it possible to run an external command and store its output in a register?
:redir
works for ex commands, not for external开发者_JAVA技巧 commands (afaik):r !
runs the external command but directly inserts output into the current buffer
Found the answer thanks to a user on the vim-use mailing list:
:let @a = system("ls -l")
To run a command with the file under the cursor as argument:
:let @a = system("ls -l " . shellescape(expand('<cfile>')))
: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).
精彩评论