更新时间:2023-10-28 09:38:34
:nmap
仅在普通模式下定义映射.对于插入模式,请使用:imap
(通常,除非您确实需要进行重新映射,否则***使用:inoremap
),并通过在<C-o>
(对于单个命令)或<Esc>
(在此处更合适)之前首先退出插入模式. ,因为无论如何您都想将缓冲区保留为:quit
.
:nmap
only defines the mapping in normal mode. For insert mode, use :imap
(in general, prefer :inoremap
unless you really need remapping to take place), and first leave insert mode by prepending <C-o>
(for a single command) or <Esc>
(more appropriate here, since you want to leave the buffer with :quit
, anyway).
:inoremap <C-s> <C-o>:wq!<cr>
顺便说一句,我发现您也想退出缓冲区很有趣.对我来说,该映射很有用,因为我可以在编辑过程中快速键入它,以便经常保留更改.
BTW, I find it interesting that you also want to quit the buffer. For me, the mapping is helpful because I can quickly type it in the middle of editing, so that I can frequently persist the changes.
" Use CTRL-S for saving, also in Insert mode
:nnoremap <C-S> :<C-U>update<CR>
:vnoremap <C-S> :<C-U>update<CR>gv
:cnoremap <C-S> <C-C>:update<CR>
:inoremap <C-S> <C-O>:update<CR>