How to break a line in vim in normal mode?

依然范特西╮ 提交于 2019-12-02 18:50:02

Try this:

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

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

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

put cursor in position and...

  r<Enter>

Similar to other answers but doesn't replace the current character.

R<enter>

No remaps required.

As far as I know this isn't possible without entering insert mode. You can however macro it with something like (replace Z with whatever key you want to use)

nmap Z i<cr><esc>k$

basically this maps the key 'Z' to enter insert mode 'i', insert a carriage return '<cr>', leave insert mode '<esc>', go up a line 'k' and finally go to the end of the line '$'

Fosco

Per this duplicate question: How do I insert a linebreak where the cursor is without entering into insert mode in Vim?

From within vim, type:

:map g i[Ctrl+V][Enter][Ctrl+V][Esc][Enter]

This maps the G key to macro I [Enter] [Escape]

You can use recording. Place your cursor where you would like to insert a line break. Type qa to start recording into register a (you can use another register other than a if you want. Then type i (switch to insert mode), Return (insert newline), escape (exit insert mode), q (ends recording.) Now you can invoke this sequence of keys by typing @a (where a is the register number you used when you started the recording, so just keep moving the cursor where you want to insert a newline and type @a.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!