Anwar
Anwar

Reputation: 4508

Efficient way to format curly braces to be inline

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?

Upvotes: 2

Views: 179

Answers (3)

anon
anon

Reputation:

For a more automated way of transforming code in both directions, consider my "splitjoin" plugin: https://github.com/andrewradev/splitjoin.vim

Being a single mapping, it would, technically, be the quickest way :)

Upvotes: 1

Ultcyber
Ultcyber

Reputation: 406

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

Upvotes: 3

Light
Light

Reputation: 1306

  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.

Upvotes: 6

Related Questions