10

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?

1
  • 1
    Assuming you want to replace the space: r<cr>
    – Ralf
    Jun 15, 2020 at 16:52

4 Answers 4

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>
2
  • 1
    Got it, thank you. Anyway, I don't think using s is a good choice, because biult-in s is very convenient. Dec 23, 2016 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, 2016 at 19:52
30

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

2

Personally, I found the following quite easy with just normal commands:

I find the space just before the word(s) I want to bring down with f <spacebar>, I cycle through them with ; and , and then I type r <Enter>. If I need to split again I just keep cycling through spaces as said above and repeat the process.

1

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.