This article introduces how to save files using Ctrl-S in the Vim command-line text editor on Linux command line or WSL Linux Bash command line. We’ll disable the Ctrl-S behavior and configure Vim to use Ctrl-S for saving.
Disabling Ctrl-S
First, disable the Ctrl-S behavior using the following commands. This prevents Ctrl-S from freezing in Linux command line or WSL Linux Bash.
cat >> ~/.bashrc
bind -r '\C-s'
stty -ixon
. ~/.bashrc
The above commands add settings to the ~/.bashrc file and disable the Ctrl-S function. Then, run . ~/.bashrc to apply the settings.
Mapping Ctrl-S in Vim
Next, add mappings to the Vim configuration file .vimrc to make Ctrl-S save in Vim. Below is the command to add Ctrl-S mappings to the .vimrc file:
cat >> ~/.vimrc
:nmap <c-s> :w<CR>
:imap <c-s> <Esc>:w<CR>a
This allows you to save files by pressing Ctrl-S in Vim. It’s also configured to save using Ctrl-S in insert mode.
By using this method, you can use Ctrl-S as a save shortcut key in Vim. You’ll be freed from the Ctrl-S freeze problem and can save files safely.
Reference: