Question

I'm little bit confused about formatting of curly braces. Assume I have following text:

[
(
{
text
}
)
]

To join all lines, I pressed JJJ... and I got:

[ ( { text }) ]

Is this a normal behaviour? Why doesn't vim join ( without spaces, whereas it suppresses white space for )?

Was it helpful?

Solution 2

From :help J (scroll down a bit, or scroll up a bit from :help replacing):

These commands, except "gJ", insert one space in place of the <EOL> unless
there is trailing white space or the next line starts with a ')'.  These
commands, except "gJ", delete any leading white space on the next line.

I am not sure why it works that way--maybe it is convenient for C editing--but it is well documented.

OTHER TIPS

you should press gJ instead of J

:h gJ

and there is :join command. you need read the :h join

for your requirement, you could:

:%j!

or first select lines, then: :'<,'>j! (vim will automatically fill the range '<,'>)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top