noremap <C-S> :update<CR>
vnoremap <C-S> <ESC>:update<CR>
inoremap <C-S> <ESC>:update<CR>
These are the binds that I have set to get Vim to respond to a Ctrl+S by saving the buffer. I don't really use this, but this is very convenient for that short period of weaning on/off or interacting with other editors which we are all occasionally forced to put up with, and which invariably only provide that single bind for committing changes.
Anyway, there are times, such as when Vim is in command-line mode (entering :
command or /
search) when pressing Ctrl+S will fail, even if I use a bind like this:
noremap! <C-S> <ESC>:update<CR>
It basically quits the command entry (apparently sending off the command or search, which is undesired also, even when I bind the <ESC>
!) and fails to run :update
.
How can I make it work if I leave Vim in command line mode but still use the bind?
The solution is to use Ctrl+C
to force the cancellation of whatever's entered. This successfully issues the following :update
.
cnoremap <C-S> <C-C>:update<CR>
A word of warning: You will need to configure your terminal/shell settings to ensure that Ctrl+S does not send a "XOFF" signal which makes it temporarily stop accepting keys (which is then subsequently switched off with Ctrl+Q). This is a one-time config thing that probably is sufficient by configuring on either the shell or terminal client.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With