Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: store output of external command into a register

Tags:

vim

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
like image 320
Matteo Riva Avatar asked Nov 07 '09 20:11

Matteo Riva


1 Answers

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

like image 86
Matteo Riva Avatar answered Sep 30 '22 06:09

Matteo Riva