Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have added this line in .vimrc so that pressing control-s saves the current file

:nmap <C-s> :w!<cr>
:imap <C-s> <esc>:w!<cr>

But this is not working. Any suggestions about what I am doing wrong?

share|improve this question
1  
I would encourage you to not use these kind of mappings, but learn the vim shortcuts. Once you use a vim on a different system, you will get lost. –  Bernhard Dec 29 '12 at 16:03

1 Answer 1

up vote 3 down vote accepted

See this wikia.com article for the exact thing you're tyring to do: http://vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_files

In a nutshell you need to do the following.

1. Add this to ~/.vimrc

" If the current buffer has never been saved, it will have no name,
" call the file browser to save it, otherwise just save it.
nnoremap <silent> <C-S> :if expand("%") == ""<CR>browse confirm w<CR>else<CR>confirm w<CR>endif<CR>

2. Disable terminal's interpretation of Ctrl+S

# bash
# No ttyctl, so we need to save and then restore terminal settings
vim()
{
    local ret STTYOPTS="$(stty -g)"
    stty -ixon
    command vim "$@"
    ret=$?
    stty "$STTYOPTS"
    return "$ret"
}

# zsh
vim() STTY=-ixon command vim "$@"
share|improve this answer
    
The solution given above works fine and solves my problem. But Here is another probelm. <TAB> doesn't work now in insert mode. When in press <TAB> cursor returns to first column of current line!! Any solutions? –  Soumen Das Dec 29 '12 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.