Search code examples
joinvimcurly-braces

vim: How to join open/close braces without white spaces


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 )?


Solution

  • 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.