![在 vim 中使用 CTRL-s 保存](https://linux22.com/image/48694/%E5%9C%A8%20vim%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20CTRL-s%20%E4%BF%9D%E5%AD%98.png)
我已在 .vimrc 中添加了这一行,以便按ctrl-s保存当前文件
:nmap <C-s> :w!<cr>
:imap <C-s> <esc>:w!<cr>
但这是行不通的。关于我做错了什么有什么建议吗?
答案1
请参阅这篇 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 "$@"