What's the quickest (as far as anyone knows) way to change this:

int main()

into this:

int main() {

provided the cursor is on the {?

  • 4
    kJ? (and some more text is here because comments need it :) )
    – grochmal
    Apr 5, 2017 at 1:18
  • @grochmal That looks like an answer, to me!
    – Rich
    Apr 5, 2017 at 8:35

3 Answers 3


It actually took me a little while to figure this out on my own, too: dh

Now, I use a macro for "merging" lines like this: let @m=' 0i ^[0wd0dhi ^[' This will take the current line, with the cursor positioned anywhere on that line and merge it with the previous line, while inserting a space, and leave you back in NORMAL mode. Note: the ^[ are escapes gotten by typing ctrl-r<Esc> which is control-r then the esc key. To be sure you've done it correctly, those two characters will behave as one if you try and move the cursor over them.

Put the above line in your ~/.vimrc or ~/.vimrc.local and then either restart vim or do :source ~/.vimrc

  • 1
    dh will result in int main(){, not int main() {, and it only works if you've added h to your whichwrap setting.
    – Rich
    Apr 5, 2017 at 8:35
  • Previous comment reads more confrontational than I meant it to! Just thought they were caveats to your otherwise nifty technique that might be worth mentioning.
    – Rich
    Apr 5, 2017 at 8:50
  • Thanks. I wasn't aware of the whichwrap setting. Learning something new every day.
    – GH05T
    Apr 5, 2017 at 13:01

Besides that I think that opening braces on a separate line is the better style, you can do


to append all occurences in the whole file of opening braces in a separate line to the previous line.

If this is your coding style (for some no good reason), you can add this to your .vimrc to be executed automatically when opening source code files.


you can use the following command in normal mode if cursor is at bracket.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.