0

I would like to have a selection that whose contents I replace with a command like r, but the replaced text is added to a register.

The use case is editing a Markdown table in Vim, where I want to remove an entry and move it around. I would like to use vAwr_ (where the underscore is a space character) and then move to another cell to paste the result with e.g. R<C-r>"

I am hoping there is a built-in way to do this, but otherwise guidance on a new keybinding that performs the equivalent task would be helpful (perhaps modifying r in visual mode so that it copies to a register before replacing.)

Another alternative is creating a new text-object to select between the | symbols of the Markdown table, but I would rather solve this general problem first.

1 Answer 1

2

Just copy text and restore the selection immediately with ygv. Then you can proceed with r_ or whatever.

If you believe that this extra three key presses is too much then make a mapping like

xnoremap r ygvr

Then every "r" in Visual mode will also copy the selection into default register first.

Your Answer

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

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