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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.