Reputation: 2223
I would like to be able to setup MacVim so that it switches back to Normal mode after saving a buffer. For example: lets say I am adding some text in Insert mode and I hit "Command + S" to save, I would like to be in Normal mode after the save operation has completed.
Is this possible?
Note: Incase the above is unclear, I do not want to spend more time in Insert mode, but less. I would like to exit Insert mode automatically upon save.
Upvotes: 1
Views: 343
Reputation: 2223
Adding the following lines to your .gvimrc
will disable MacVim's [Cmd + S] shortcut, and switch the mode back to Normal before saving.
It will also block Vim from entering Insert mode when hitting [Cmd] + [S] keys (as this would have activated the substitute command). Note: you will still be able to substitute hitting the [S] key as usual.
" Disable MacVim save shortcut
macmenu File.Save key=<nop>
" Exit to Normal mode upon [Cmd+S]
inoremap <D-s> <Esc>:w<CR><Right>
vnoremap <D-s> <Esc>:w<CR>
" Save in Normal mode (block Substitute)
nnoremap <D-s> :w<CR>
Thanks to @Amadan for pointing me in the right direction.
Upvotes: 2
Reputation: 198324
Wanting to typically be in insert mode is using Vim wrong. If it works for you, that's fine; but you will never reach the potential of Vim while sticking to that habit; might as well use Notepad++/SublimeText3/...
If you really really want it, you can have something like :inoremap <C-s> <C-o>:w<CR>
to save and stay in insert mode, or :inoremap <C-s> <Esc>:w<CR>
to save and move to normal mode. (It will work only on graphical Vim, as terminal Vim typically won't ever receive Ctrl-S.)
Upvotes: 0