1

Inside a function, saved multiple lines of external command output to a variable.
How to delete a line from the variable? Like first line.

I can run let tmp = split(variable, "\n") to assign the variable to a tmp list, then delete an item. Not sure if there is any easy way.

0

You may try this substitute command to delete, e.g the 3rd line

substitute(var, '\v^((.{-}\n){2}).{-}\n(.*)', '\1\3', '')

The regex works as follows

  • ^((.{-}\n){2}) matches the first 2 lines and capture it in group \1
  • .{-}\n matches the next line
  • (.*) matches the rest of the variable and capture it in group \3

\{-} matches 0 or more of the preceding atom, as few as possible

4

It depends on how you get the result of your external command but you might be interested in :h systemlist().

It executes the command given as parameter and returns a list containing every lines of the output. You can then use :h list-functions on the result or simply listVar[1:].

I think that is more robust and portable than matching the lines and doing some substitutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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