In vim, "J
" joins the next line to the current line. Is there a similar one-key (or relatively short) command to split a line at a given cursor position? I know it be done with a simple macro, but it seems like if the J
-command exists there should be a similar function. I've tried searching for it, but can't seem to find an answer.
views:
2755answers:
8No. I've now read enough answers to conclude that there is no such command.
Easy answer: Pressing 'Enter' while in insert will do it; but you're right, there oughtta be a key for it in command mode. I've wondered, too.
Since everyone has a favorite workaround, I will share mine. The assumption is that I will do anything to avoid having to reach for the Esc key.
ylprX ... where 'X' is the inserted character, which can even be a newline.
So, 'yl' is yank on char to the right, 'p' = paste the char, 'r' is replace that char; then you just type the new char. That's how much I hate using Escape.
(That was 'l', as in "move right", BTW)
I don't think that there is a single key command for this. The best you can do with stock vim is probably "i+<Enter>".
Does this help? How do I insert a linebreak where the cursor is without entering into insert mode in Vim?
You can split lines if you can create a regular expression for the location to add the split. For example if you want to split the lines at each semicolon, you can use the following substitution:
%s/;/^v^m/g
to great effect
@gbarry: wow. That's serious salidaphobia. It just so happens the keystroke '^[' (that's Control-[) is mapped to the escape sequence in Vim. Next time you take a vacation up north to the Esc key, you can see that sequence register on the bottom line of your window.