1

This would be particularly useful for macros, i.e., select visually the exact lines I want to perform the macro on, and then run the macro. But currently when it finishes the first action, the visual selection turns off, so the next action only works on the current line.

Example macro:

: auto-inserted '<,'> w ^R0.extension | d^M

(Where the 0 register is known to have a legal filename in it with no spaces.)

I'm trying to extract visually selected lines to a different file, and a macro along with Ex-mode commands would do nicely, IF I could get the Ex-mode commands to work more than once on the same selection.

How can I do this?

  • After the visual mode finishes, use gv to reselect or simply manually use the marks '<,'> they are still valid even if visual mode was finished. – Christian Brabandt Oct 18 '15 at 7:22
  • Ah! Perfect. That is an answer; you should post it as such. :) – Wildcard Oct 18 '15 at 7:25
  • Okay, then I will do. – Christian Brabandt Oct 18 '15 at 7:31
2

Although visual mode finishes after you call your command, the marks '< and '> remain valid. So if you need to call additional commands you can simply use those marks again. They won't be added automatically, so you need to add them manually.

Alternatively, you could reselect the last visual area using gv and call your next Ex command and those marks will be added automatically again.

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.