6

We can make from two lines a single with J. It looks as the following:

line 1
line 2

after J pressed on line 1 we've got this:

line 1 line 2

But is there a combination which what do the opposite (not u)? I mean to split

line 1 line 2
      ^
   cursor

in

line 1
line 2

i<ENTER><ESC> is too messy. Is there a one button shortcut for this in vim already?

7

As far as I know, vim doesn't have a command for this. But vim is also all about customization. Easy enough to make your own mapping!

nnoremap s i<CR><Esc>
  • 1
    Got it, thank you. Anyway, I don't think using s is a good choice, because biult-in s is very convenient. – Dmitrii Bundin Dec 23 '16 at 19:46
  • You're welcome to bind it to whatever you want. :) Just chose s originally because split is a good mnemonic. – Tumbler41 Dec 23 '16 at 19:52
24

For your specific case, when you have a space, that you also like to get rid of, I usually use rEnter

0

The easiest way I've found to split lines in Vim is the normal mode command gq (type both letters in quick succession in normal or visual mode).

In visual mode, it will split whatever is selected, in normal mode, you follow gq with a motion.

For example, gql will split one line to the currently set width. To set the width of the split lines to be different from your current setting, you can use :set textwidth=n, where n is the number of characters you want in a line, e.g., 10 and change back to your normal width when you're done.

Got this information from a Youtube video by Kholidfu that shows how to join and split lines in normal mode using a motion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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