简体   繁体   中英

How can I map keys in Insert mode that contains Carriage Return in it?

How can I map ctrl + enter to go to new line from anywhere in the current line in vim ? I just want to do it for insert mode. I tried

:set <C-<CR>> <Esc>o

but that doesn't seem to work.

For an insert mode mapping, you need :imap ; :set is for setting Vim options. Ctrl + Enter is written as <C-CR> ; cp. :help key-notation . Ergo:

:inoremap <C-CR> <Esc>o

Note that this key combination mostly only works in GVIM, as most terminals do not send different keycodes for Enter in combination with modifier keys. If you need a solution that also works in terminals, you need another key (combo), eg <Cg><CR> .

For Windows Users:


Solution 1

On windows Terminal-App, CMD or Powershell the Ctrl+Enter is getting translated to Ctrl+j and so you can do:

:inoremap <C-j> <ESC>o
vim.keymap.set('i', '<C-j>', '<ESC>o')

示范


Solution 2

The preferred way is to use the "Keyboard Manager" utility of PowerToys and target any app you want to remap it's keys , like: PowerToys 键盘管理器实用程序


References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM