4

Sometimes I write something in brackets and then realize I've typed the wrong kind. For instance, in LaTeX:

\command(arguments)

Which should be:

\command{arguments}

I can jump between the two parentheses/braces using %, but since % doesn't work after the opening delimiter has been changed, in order to change both of the braces I have to do something like:

%r{f)r}

This doesn't seem like a big deal, but I find that switching from brace to parenthesis in the middle of the command sequence creates a surprising amount of cognitive dissonance, and this task often takes much longer than it feels like it ought to. Is there a plugin or simple hack that would provide an easier way? I would like it to be able to handle multiple pairs on the same line, so a simple substitution won't work, and I'd rather not define separate mappings for every pair of delimiters I'd like to convert between. (Just off the top of my head, ', ", (), {}, and [] are all in the list I need to convert between, and I'd probably sooner or later find a use for <> as well.)

A related problem is entirely removing a pair of brackets -- say I'm writing prose and have a sentence in parentheses and then decide it shouldn't be in them anymore. I can use da( to get rid of the whole clause, or di( to get rid of the content, but I want to get rid of the parentheses. The resulting command %xf)x is much less annoying, but there's still some room for improvement.

  • 3
    You will love Surround. – romainl Apr 8 '16 at 12:34
  • @romainl shouldn't that be an answer? – mMontu Apr 8 '16 at 12:35
  • 1
    @romainl That's hilarious – I have Surround, but I never knew it could change or delete existing delimiters! I guess I should read the documentation every now and then to see what I'm forgetting. – Soren Bjornstad Apr 8 '16 at 12:36
  • (And if you put that as an answer with a brief summary of the commands I'll be happy to accept it.) – Soren Bjornstad Apr 8 '16 at 12:39
7

Surround does what you want and more:

ds(    delete first surrounding pair of parentheses
2ds(   delete second surrounding pair of parentheses
cs[{   change surrounding pair of square brackets into a pair of braces

See :help surround.

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.