Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enclosing curly braces in parenthesis with Vim?

Tags:

vim

How to enclose curly braces in parenthesis in vim? Initial string:

{a: b}

Final string:

({a: b})

The string possibly span multilines:

{
  a: b
}
like image 217
Yohei Avatar asked Dec 14 '25 04:12

Yohei


1 Answers

Assuming you are in normal mode and on any curly bracket character (opening or closing). The manual/vanilla version (without any bracketing plugin) would be

c%(^R")

With:

  • ^R meaning CTRL+R
  • the default register (") being filled with the content of the dictionary.
  • ca{ that should be used instead of c% if you're anywhere within the dictionary.

With my lh-brackets plugin, I would use v%( or vi{( -- unlike the vanilla version, will leave the default register unmodified.

With the popular surround plugin, I guess (I may be wrong as I've been using my plugin for decades) it would be something like ys%( or ysa{(.

PS: the fact your dictionary spans on several lines doesn't make any difference here.

like image 84
Luc Hermitte Avatar answered Dec 16 '25 22:12

Luc Hermitte



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!