tags:

views:

2755

answers:

8

Duplicate: http://stackoverflow.com/questions/237383/how-do-i-insert-a-linebreak-where-the-cursor-is-without-entering-into-insert-mode

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.

+4  A: 

No. 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)

gbarry
I'm gonna go file a feature request. Who's with me?!
dburke
To "improve" vi again? (Big grin). My guess is if everyone wants it and it doesn't exist, there must be a reason. What I *really* want is an "insert n characters" cmd that stays out of "insert mode".
gbarry
Recommended: http://stackoverflow.com/questions/397229/reaching-up-to-hit-the-escape-key
dreeves
Thank you! Upvote coming your way!
gbarry
@gbarry Wow - have you considered remapping CapsLock to do the Esc function?
willoller
+6  A: 

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>".

Brian Pellin
A: 

Does this help? How do I insert a linebreak where the cursor is without entering into insert mode in Vim?

bedwyr
No, I as really looking to see if maybe there was some base command I had overlooked or been unable to find that someone else here might know.
dburke
A: 

If you are in insert mode, pressing ENTER will split the line.

Klinger
+9  A: 

r<Enter> while on whitespace will do it. That's two keystrokes.

Kristo
Close, but no cigar. I'm often wanting to split between two adjacent html tags with no space between.
dburke
A: 

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

Jed
A: 

Jed's answer is most useful. I would like to add that I needed the "control-V-alternative", i.e. control-Q: %s/;/^q^m/g

A: 

@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.

acy