tpope / vim-surround

surround.vim: Delete/change/add parentheses/quotes/XML-tags/much more with ease

Home Page:https://www.vim.org/scripts/script.php?script_id=1697

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Request] Swap in quotes

jrocketfingers opened this issue · comments

A thing I find myself doing often is selecting an item that needs to be swapped into quotes or parentheses in a few places.

Doing a di" nukes the default yank register, so I need to do "_di"p, which isn't too bad, but it feels like it could be a thing of it's own. Something like "swap in quotes".

If this is too niche, I'd love to hear a way of constructing this through vim mappings.

I run into this too, although more often than a string it's a multi-line block of code. And seeing how it's not specific to strings/surroundings, I don't think it fits with surround.vim.

I'd love to hear a way of constructing this through vim mappings.

If the string case is the common one, you could literally map something to "_di"p. If you want to allow arbitrary targets, you could do it with an 'opfunc'. This wouldn't be that hard, but it's fiddly enough that I'm not gonna take the time to implement it myself.

Oh, from :help v_P, this sounds extremely close to what you want:

With |P| the unnamed register is not changed (and neither the selection or
clipboard), you can repeat the same change. But the deleted text cannot be
used.

So vi"P would do what you want. That's about as short as any general purpose map would be.

Awesome, it's not just the shortness, it's the "flow" of vi"P that doesn't require backtracking which makes it so nice. Thanks @tpope!