tamuhey
tamuhey

Reputation: 3525

Enclosing curly braces in parenthesis with 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
}

Upvotes: 2

Views: 1062

Answers (2)

Drenai
Drenai

Reputation: 12347

With the vim-surround plugin you can visually select the text first e.g. va{, then surround with parentheses using S). I find it easier to remember this visual surround sequence v{motion}S<char> than the other options

Upvotes: 4

Luc Hermitte
Luc Hermitte

Reputation: 32926

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.

Upvotes: 7

Related Questions