Pages

Thursday, November 14, 2013

Vi and CTRL + S

As a System administrator I use Putty almost every day. There are cases where I try to save the file opened in a vi editor using CTRL+S and I do this when I open the file in Putty.

When I press the CTRL+S , putty seems to be hang without accepting any of the key board commands. I have to kill the Putty and start it again.

So what exactly happens here is when we press CTRL + S , it actually does a XOFF which means terminal will accept key strokes but won’t show the output of anything.We cant see any of the key strokes going on but actually the key strokes are being sent to the terminal.

In Order to disable the XOFF , we can then press CTRL+Q to turn flow-control on (XON) to see the key strokes again.

In Order to disable this we can add .bashrc file like
stty ixany
stty ixoff -ixon

and for using CTRL + S to actually save the file in vi. Add the below as they are
 in  .bashrc

# turn off Ctrl + s XOFF (XON is Ctrl + q)
stty ixany
stty ixoff -ixon
stty stop undef
stty start undef

.vimrc :
” Ctrl+s to save
map <C-s> :w<cr>
imap <C-s> <ESC>:w<cr>a

” Ctrl+q to quit, hold shift to discard changes
map <C-q> :q<cr>
imap <C-q> <ESC>:q<cr>
map <C-S-q> :q!<cr>
imap <C-S-q> <ESC>:q!<cr>


More to Come, Happy learning J