Vim

在 vim 中使用 CTRL-s 保存

  • December 12, 2016

我在 .vimrc 中添加了這一行,以便按ctrl-s保存目前文件

:nmap <C-s> :w!<cr>
:imap <C-s> <esc>:w!<cr>

但這不起作用。關於我做錯了什麼的任何建議?

請參閱此 wikia.com 文章了解您想要做的確切事情:http: //vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_files

簡而言之,您需要執行以下操作。

**1.**添加到~/.vimrc

" If the current buffer has never been saved, it will have no name,
" call the file browser to save it, otherwise just save it.
nnoremap <silent> <C-S> :if expand("%") == ""<CR>browse confirm w<CR>else<CR>confirm w<CR>endif<CR>

**2.**禁用終端對Ctrl+的解釋S

# bash
# No ttyctl, so we need to save and then restore terminal settings
vim()
{
   local ret STTYOPTS="$(stty -g)"
   stty -ixon
   command vim "$@"
   ret=$?
   stty "$STTYOPTS"
   return "$ret"
}

# zsh
vim() STTY=-ixon command vim "$@"

引用自:https://unix.stackexchange.com/questions/59770