Reputation: 83
I have recently switched from using MacVim to just using Vim on the command line. One feature I miss is being able to save a file with ⌘S rather than having to go back into normal mode and then :wq
I am using Vim inside iTerm2. Is there any way to get ⌘S to save a file both in insert and normal mode?
Upvotes: 4
Views: 2824
Reputation: 985
Here is an even simpler way to do it: using iTerm2's "Send Text". Basically you can map Cmd-S
to send a text to the current vim session :w\n
.
Upvotes: 4
Reputation: 15942
You can use iTerm2 to map Cmd-S
to some other combination that the shell and Vim will recognize (e.g. Ctrl+S
) , then you can simply map that command via a .vimrc file as Andrew pointed out.
In summary:
Ctrl+S
.Ctrl+S
to vimrc file (like Andrew describes) or like this site.Upvotes: 5
Reputation: 42
It is not possible to map to ⌘ in the console version of Vim. If you want to be able to use ⌘ in a mapping you'll need to switch back to MacVim.
Upvotes: 0
Reputation: 474
Well, I'm not sure that command-line Vim can register the ⌘ key, and I'm not on my Mac to confirm, but you can map ⌘S in .vimrc like this.
inoremap <D-s> <ESC>:w<CR>i "insertmode
nnoremap <D-s> :w<CR> "normalmode
Again, this will only work if command-line vim can recognize the ⌘key.
Upvotes: 1