更改CTRL + S以在Vim中保存文件时,TAB不起作用 [英] TAB not working when changing CTRL+S to save file in vim
问题描述
我尝试使用 CTRL + S 在vim中保存文件.我碰到了此链接 http://vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_files,并据此分别在.basrc和vimrc中添加了以下代码段:
I tried to save a file in vim by using CTRL+S. I came across this link http://vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_files and according to it added these pieces of codes in .basrc and vimrc respectively:
vim()
{
local STTYOPTS="$(stty --save)"
stty stop '' -ixoff
command vim "$@"
stty "$STTYOPTS"
}
和
nmap <C-s> :wq!<cr>
现在确定 CTRL + S 保存文件.但是 TAB 在插入模式下现在不起作用.当我按 TAB 时,光标返回到当前行的第一列!有解决方案吗?
Ok now CTRL+S saves the file. But TAB doesn't work now in insert mode. When I press TAB, cursor returns to first column of current line!! Any solutions?
推荐答案
: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>
这篇关于更改CTRL + S以在Vim中保存文件时,TAB不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!