Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break a line in vim in normal mode?

Tags:

vim

macvim

I would like to break a line (at the location of the cursor) in to two lines without leaving normal mode (entering insert or command-line mode). Is this possible?

I currently get to the location I want and hit 'i' to enter insert mode, 'enter' to break the line in two, then 'esc' to return to normal mode.

I am not trying to set a maximum line length or do any syntax or anything like that. I just want to break one line into two lines without leaving normal mode. 'J' joins the line the cursor is on to the line below it, which is handy. I want the opposite -- to break one line into two with a single command.

like image 742
Ted Avatar asked Oct 18 '10 17:10

Ted


People also ask

How do I go to normal mode in Vim?

By default, Vim starts in “normal” mode. Normal mode can be accessed from other modes by pressing Esc or <C-[> .

How do I change a whole line in Vim?

Use c$ or just C to quickly change from the cursor to the end of a line, cc to change an entire line, or cis for a sentence. The standard change word command requires you to type cw , then a new word, then press Escape.

How do we make a new line under the current line Vim?

Press Enter to insert a blank line below current, Shift + Enter to insert it above.


2 Answers

Try this:

:nnoremap <NL> i<CR><ESC> 

then just press Ctrl-J whenever you want to split a line.

like image 150
Amardeep AC9MF Avatar answered Sep 25 '22 06:09

Amardeep AC9MF


I don't know of a single key command, but a lot of times I do "r" then "Enter" to break a line.

"r" replaces the current character under the cursor without going into insert mode. This may not be what you want if you don't want to replace a character...

like image 35
Andy White Avatar answered Sep 22 '22 06:09

Andy White