问题
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