Bind in Vim

terminal

Is it possible to map to save in vim in a standard terminal? I know how to set it in my vimrc but am not sure if it is possible to pass it from terminal to vim instead of attempting to save the terminal.

Best Answer

Yes you should be able to set up a key mapping in your .vimrc file so that when you press command - S it maps to :w Also here is something else to go on that you can modify as well Map Ctrl-S to save current or new files

  • First thing is to reassign the the Command - S functionality for the Application. Do this in the Keyboard > Keyboard Shortcuts System Preference Pane.

For example, you will want to add in a new Application Short cut for the Terminal app, then map to the Menu title "Export Text As..." to another keyboard command something that you don't use, e.g. control - s or etc. should be fine.

Something such as this noted below* you can add to you .vimrc:

:map <M-s> :w<kEnter>  "Works in normal mode, must press Esc first"
:imap <M-s> <Esc>:w<kEnter>i "Works in insert mode, saves and puts back in insert mode"

*This was verified working on the X11 terminal on OS X Lion.