How can I map Command S
to :w
in vim?
I have tried everything from other threads but nothings seems to work in Mac OS X El Capitan.
This supposedly worked in previous versions, but I tried it, and had no success.
noremap <silent> <C-S> :update<CR>
vnoremap <silent> <C-S> <C-C>:update<CR>
inoremap <silent> <C-S> <C-O>:update<CR>
Everything on this topic that I could find is several years old and doesn't work anymore. I could find this thread or this thread, but they are both more than three years old and no longer work. That is why I am asking for the current version of Mac OS X (El Capitan)
<C-
is the notation for the Control key. It's <D-
for the Command key.
The Command key is only visible to MacVim and only when using the GUI front end. No matter what Vim you use in Terminal.app or iTerm.app (MacVim or any other build), it will never see the command key.
In other words, you can't expect <D-
mappings to work in CLI Vim. It is simply impossible.
The only way to get CLI Vim to do anything upon pressing Cmd+something on Mac OS X is to map that combo in your terminal emulator to emulate pressing on another key, itself mapped to the desired command in Vim.
In ~/.vimrc
…
nnoremap <F6> :w<CR>
In iTerm.app…
FYI, 0x112
is <F1>
, 0x113
is <F2>
, etc. My choice of <F6>
is arbitrary, use whatever works for you.
In Terminal.app…
I don't have El Capitan so I have no idea of what can be done in the new Terminal.app but its previous incarnations didn't allow you to remap arbitrary keys — only a predefined set — so I don't think it's doable here without some hypothetical third-party tool.
The whole idea of using Cmd+S in Vim is very bad. Get used to the Vim way instead.