When I use Vim on the terminal and I run Ctrl + S , or the terminal hangs or something strange happens.
When I use Vim on the terminal and I run Ctrl + S , or the terminal hangs or something strange happens.
Ctrl-S
is a shortcut to enable the terminal's scroll-lock since when the terminals were slower to display the characters than the operators typing them. To turn off scroll-lock, just press Ctrl-Q
.
Since you need to use this key combination in Vim, you need to configure the terminal to disable scroll-lock on some terminals, such as xterm
. This can be done by adding the allowScrollLock: "false"
option in the ~/.Xresources
file.
After that, just set up Vim (file ~ / .vimrc) with map!:
map! <C-s> <ESC>:w<CR>
Note: If you need to map to all Vim modes, you need to use map!
and map
, the first is used for the Insertion and Command Line modes, the second for Normal, Visual / Selection and Pending Commands.
I think the problem is that Ctrl + S is the shortcut of the "Stop" command, and so it is locking your terminal. Have you tried using the "stty" command ( link ) to configure the terminal ?
I can not test here, but it seems to me that one possibility is to create a script that does something like:
stty -ixon
vim
stty ixon
According to the stty documentation, the ixon option does the following:
ixon (-ixon) Enable (disable) START/STOP output
control. Output is stopped by sending
STOP control character and started by
sending the START control character.
In Vim you save it like this (you only need ESC if you are not in command mode):
I would use :inoremap <c-s> <c-o>:update<CR><CR>