Efficient way to format curly braces to be inline

Viewed 72

What is the quickest way to move curly braces to be on the same line?

from this:

const value = { 
    input: 123 
}

to this:

const value = { input: 123 }

The way I do it is by using Visual with a combination of hjkl.

Bonus: How can I achieve the edits but the other way around?

3 Answers
  1. Place cursor at or before the first {.
  2. Press v, then shift+%.
  3. Press shift+j.

Note: the behavior may break if unpaired { or } exists in comment/string/etc.

Put cursor at first line (const...) and then press J repeatedly until all the code is on one line.

If you haven't bound Caps lock to anything else, you can press it before to avoid holding Shift

Related