插入新行时不要进入插入模式

我想插入换行在正常模式下的 vim 使用 Shift-EnterCtrl-Enter。我尝试了一些来自 Vim Wikia-不进入插入模式插入换行符的溶液和混合溶液,但是 Shift-EnterCtrl-Enter没有反应:

" put a new line before or after to this line
nnoremap <S-CR> m`o<Esc>``
nnoremap <C-CR> m`O<Esc>``


" reverse J command
nnoremap <C-J> vaW<Esc>Bi<CR><Esc>k:s/\s\+$//<CR>$
55987 次浏览

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today. (This particular case should work in GVIM, though.) Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + <C-I>1 vs. Ctrl + <C-I>3 + <C-I>1 cannot be distinguished. (Unless your terminal sends a distinct <C-I>5 code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This also applies to <Tab> / <C-I>, <CR> / <C-M> / <Esc> / <C-[> etc. (Only exception is <BS> / <C-H>.) This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals.

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

My alternative is using oo (resp. OO) to insert a new line under (resp. over) the current through this mapping: nmap oo o<Esc>k (resp. nmap OO O<Esc>j)

I use :s/\n/\r\r/g (subsitute the newline with two newlines, which is the same as "o").

This is what I use:

nmap <CR> :a<CR><CR>.<CR>

I tried nmap <CR> o<Esc>, but it made UI glitchy as it was switching to insert mode and back.

You can use a hack to do this.

In edit mode, you can use p to paste the current clipboard. Since o adds a newline, you can use o<ESC>ddp to add a new line below the cursor; from there, p will add a new line until you delete something else.

Yank an empty line and shift-paste it:

Starting with cursor on empty line:

yy + (shift + p)

"yy" yanks the line, and "shift + p" insert it below, without entering insert mode.

How about this if you just don't want to press ESC

yypd$