TAB not working when changing CTRL+S to save file in vim

早过忘川 提交于 2020-01-07 02:31:11

问题


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"
}

and

nmap <C-s> :wq!<cr>

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?


回答1:


: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>


来源:https://stackoverflow.com/questions/14088778/tab-not-working-when-changing-ctrls-to-save-file-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!