在vim中,如何将"save"(:w)映射到ctrl- s.
我正在尝试"映射"命令,但是当我按下时,xterm会冻结ctrl- s.
如果我给ctrl- v,ctrl- s我仍然只看到一个^,而不是^S.
Ned*_*der 109
Ctrl+ S是终端停止更新的常用命令,它是一种减慢输出的方法,因此您可以在没有回滚缓冲区的终端上读取它.首先要了解是否可以配置xterm以将Ctrl+ S传递给应用程序.然后这些map命令将起作用:
noremap <silent> <C-S> :update<CR>
vnoremap <silent> <C-S> <C-C>:update<CR>
inoremap <silent> <C-S> <C-O>:update<CR>
Run Code Online (Sandbox Code Playgroud)
顺便说一句:如果Ctrl+ S冻结您的终端,请输入Ctrl+ Q以使其再次运行.
Eri*_*ski 66
在使用VI的linux中,您想按Ctrl- S并保存文档.这对我有用,在你的.vimrc文件中放入以下三行.此文件应位于您的主目录中:/home/el/.vimrc 如果此文件不存在,您可以创建它.
:nmap <c-s> :w<CR>
:imap <c-s> <Esc>:w<CR>a
Run Code Online (Sandbox Code Playgroud)
第一行说:按Ctrl- S在文档中将执行:w <enter>键盘组合.
第二行说:按下Ctrl- S在"插入"模式下文档内将退出到正常模式,执行a :w <enter,然后按a返回插入模式.在此事件期间,您的光标可能会移动
您可能会注意到Ctrl- 按下- S执行"XOFF"以阻止接收命令(如果您使用的是ssh).
要解决此问题,请将这两个命令放在〜/ .bash_profile中
bind -r '\C-s'
stty -ixon
Run Code Online (Sandbox Code Playgroud)
这样做是关闭Ctrl- S并在按Ctrl- 时删除任何XOFF屏幕消息S.请注意,在对.bash_profile进行更改后,必须使用命令'source .bash_profile'或logout/login重新运行它.
更多信息:http://vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_files
alias vim="stty stop '' -ixoff; vim"
Run Code Online (Sandbox Code Playgroud)
为什么?,发生了什么?看到这里,但基本上对于大多数终端ctrl+s已经用于某些东西,所以这个别名是vim,所以在我们运行vim之前我们关闭那个映射.
nmap <c-s> :w<cr>
imap <c-s> <esc>:w<cr>a
Run Code Online (Sandbox Code Playgroud)
为什么?发生了什么?这个应该是非常明显的,我们只是映射ctrl+s到不同的击键,这取决于我们是处于正常模式还是插入模式.
我有一个帖子.
VIM
# ~/.vimrc
nnoremap <c-s> :w<CR> # normal mode: save
inoremap <c-s> <Esc>:w<CR>l # insert mode: escape to normal and save
vnoremap <c-s> <Esc>:w<CR> # visual mode: escape to normal and save
Run Code Online (Sandbox Code Playgroud)
zsh(如果你使用的话)
# ~/.zshrc
# enable control-s and control-q
stty start undef
stty stop undef
setopt noflowcontrol
Run Code Online (Sandbox Code Playgroud)
bash(如果你使用的话)
# ~/.bash_profile or ~/.bashrc
# enable control-s and control-q
stty -ixon
Run Code Online (Sandbox Code Playgroud)