Is totally possible to map cmd+s
or any cmd
combination by using Iterm2 and a custom map key map binding.
So, to map cmd+s
to save in terminal vim you first need to make a change in Iterm2 configuration:
- Go to
Preferences -> Keys
and press the +
button in the bottom of the window, then, add the keyboard shortcut and select the action named Send text with "vim" Special Chars
and the special chars: \<C-s>
(note the \
prefix), like this:

- Second, go to the vim configuration and add a map like this:
noremap <silent> <C-s> :w<CR>
inoremap <silent> <C-s> <ESC>:w<CR>i
Note that Iterm2 will convert the keystroke cmd+s
to ctrl+s
and send it directly to vim. So you can make some other things with this in mind. For example, you can disable cmd-w
(which normally will close the window in Iterm2) and send directly to vim as <C-w>
to split windows, in this case you don't need to change anything in the vim side, only map <cmd-w>
to \<C-w>
in Iterm2. Additionally, you can disable cmd+p
to prevent the annoying Iterm2 print dialog and call :fzf o something like that in vim.
The only downside is that you need to create all the maps individually:

Btw, if you want to map some "really special" keys like cmd+/
(for example to comment lines with NERDCommenter), you need to do a slightly different keymap by using the "Send Scape sequence" action:

and then, in vim, set the map for the ^[/
keystroke (note that the special ^[
symbol is made by pressing <ctrl-v>
and then <esc>
).
