tags:

views:

346

answers:

1

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
+8  A: 

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

kemp
It's wise to use the `shellescape()` function when building shell commands. In this example, `:let @a = system("ls -l " . shellescape(expand('<cfile>')))`.
jamessan
Good point, updating the answer
kemp