6

I know I can use ranges/marks with the ! command like so:

%! column -t

etc. Is there any way to pass a register to the external command instead of the current buffer? I imagine it would look something like this @n! column -t but this just prints the contents of n with the "not an editor command" error. Do I just have to resort to putting the contents of the register in a temporary buffer and then running the command?

1 Answer 1

7

Not with the ! command. You'll have to use system instead. From :h system():

system({expr} [, {input}])              *system()* *E677*
        Get the output of the shell command {expr} as a string.  See
        |systemlist()| to get the output as a List.

        When {input} is given and is a string this string is written
        to a file and passed as stdin to the command.  The string is
        written as-is, you need to take care of using the correct line
        separators yourself.
        If {input} is given and is a |List| it is written to the file
        in a way |writefile()| does with {binary} set to "b" (i.e.
        with a newline between each list item with newlines inside
        list items converted to NULs).
        When {input} is given and is a number that is a valid id for
        an existing buffer then the content of the buffer is written
        to the file line by line, each line terminated by a NL and
        NULs characters where the text has a NL.

So putting this all together, you could do

:call system("column -t", getreg("@n"))

Now, unfortunately, this on it's own doesn't produce any output into the buffer. So if you want it to go into your buffer, you'll have to use put

:put =system("column -t", getreg("@n"))
1
  • 2
    i think it should be getreg('n')
    – Mass
    Sep 25, 2019 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.