开发者

VIM: store output of external command into a register

开发者 https://www.devze.com 2022-12-11 07:18 出处:网络
Is it possible to run an external command and store its output in a register? :redirworks for ex commands, not for external开发者_JAVA技巧 commands (afaik)

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号