Is there a command to split lines in Vim?

Solution 1:

No, there's no built-in command for that.

When I want to split on a <Space>, I do r<CR>.

--- EDIT ---

@keith-nicholas' comment reminded me about this question. FWIW I came up with an hopefully "universal" method in the mean time:

function! BreakHere()
    s/^\(\s*\)\(.\{-}\)\(\s*\)\(\%#\)\(\s*\)\(.*\)/\1\2\r\1\4\6
    call histdel("/", -1)
endfunction

nnoremap <key> :<C-u>call BreakHere()<CR>

Solution 2:

a Enter Esc to split to the right of the cursor, or i Enter Esc to split to the left.

Solution 3:

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=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: Vim Tutorial - Join and Split Lines.