For example, I've used redir command to redirect command output to register a.
Register a contains several lines of text.
How to remove a line from register a or substitute a string from it?


The register a is stored in variable @a. If you need a little bit more control you can access the register through the functions setreg() and getreg().

Substitution can be accomplished though the function substitute(), filtering can be done with filter() (but you may need to convert the string into a list first with split(str, "\n"))...

| improve this answer | |
  • You can also use execute() as an alternative to :redir, e.g. let foo = execute('ls'). See :h execute(). execute() requires Vim 7.4.2008+ – Peter Rincker Sep 4 '18 at 14:13

You can also make edits interactively by:

  • pasting the register contents into your buffer: "ap
  • editing with whatever Vim commands you like
  • and then yanking or deleting back into the register with e.g. "adip
| improve this answer | |

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.