简体   繁体   中英

Vim key mappings in insert mode

I have edited my .vimrc file and mapped some commands. They are only working in normal mode. Is there any way to map commands in insert mode? (eg commands involved with special keys such as Ctrl) For example, can I copy in insert mode using Ctrl+c?

The first letter in the :map commands determines which modes ( :h map-modes ) they apply to. So :nnoremap is for n ormal mode, and :inoremap for insert mode.

You usually cant' just use the same right-hand side ; you need to consider that you're in a different mode. To invoke a (normal mode) command from insert mode:

  • prepend <Esc> if you want to stay in normal mode after the mapping
  • prepend <Co> if you want to continue in insert mode after the mapping; this command switches to normal mode for just one command

For example, to map :w to <Cs> , you'd use this: :nnoremap <Cs> :w<CR> . The corresponding insert mode mapping (staying there) is:

:inoremap <C-s> <C-o>:w<CR

See :help imap . You can map keys, including keys with control, to various things within insert mode. For instance, if you wanted to copy the current word in insert mode with Ctrl+c you could use

inoremap <C-c> <esc>yiwea

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