Without exiting normal mode, joining two lines is easy: J
But splitting and auto-indenting a line is a little awkward:
| Context | Keyboard |
|---|---|
| Splitting on cursor | iEnterEsc |
| Splitting on one char of whitespace | rEnter |
| Splitting on more than one char of whitespace | ciwEnterEsc |
vim-split-line gives the :SplitLine command. Without leaving normal
mode it:
- Splits the line under the cursor
- Remove trailing whitespace on first line
- Auto-indents second line
Install with a plugin manager.
nnoremapS:SplitLine<CR>I use S because the default behaviour is almost identical to cc, and it has a nice symmetry with J.
You don't actually need this plugin, the below also works:
nnoremapS:keeppatterns substitute/\s*\%#\s*/\r/e <bar> normal! ==<CR>