I want to write function that passes current line and file to external program and saves its output into register, e.g:

function Foo()
  let l:current_line = line(".")
  let l:current_file = expand("%:p:S")
  let @" = system("command-foo " . l:current_file . " " . l:current_line

Problem with that code is that if external command fail, function will succeed, but will store error message into register instead of regular output. How can I get exit code of system invocation, so I can do error checking?

  • Welcome to Vi and Vim! Thanks for looking for a duplicate of your own question too...
    – filbranden
    Jun 13, 2020 at 19:19


Browse other questions tagged or ask your own question.