Ya Zhuang
Ya Zhuang

Reputation: 4660

How to map cmd+s to save all?

I'm developing some front-end project with the help of Yeoman.

I run the developing webserver by grunt serverand, because there is livereload.js in the project, for watching files change and refreshing the webpage, sometimes, I need to modify multiple files for one purpose(.html, .css, .js ...) and it's kind of waste for browser when each file saves.

So is there a way for MacVim, map cmd + s to :wa ?

Upvotes: 2

Views: 703

Answers (2)

Will
Will

Reputation: 4155

I know this is old but I came searching with the same question.

tl;dr: ++S to save all.

You can, supposedly, map <D-s> to :wa but it's not as simple as adding the mapping to your .gvimrc file. See the third bullet below.

From the MacVim docs:

cmd-key cmd-shortcuts

Creating key mappings that involve the Cmd key ( in Vim notation) can sometimes be slightly involved. Here are all the things you need to consider:

  • Make sure the shortcut is not used by a menu item by looking through the menus. If it is then you need to unbind it before you can map to it. This is described under the help for the |:macmenu| command.

  • Bindings to are case sensitive: is not the same as . If you want to map something to Cmd+Shift+d, then you need to use , not or .

  • Some command key shortcuts are reserved by Mac OS X and cannot be mapped to (e.g. ). However, some of these shortcuts can be freed up in the System Preferences under Keyboard (e.g. Cmd+Space).

The good news? In trying to sort this out I realized that MacVim is a very courteous MacVim indeed and implements, by default anyway, many standard Mac shortcuts including: ++S for "Save All". Open MacVim, click the file menu and then hit the option key to see it in action.

Upvotes: 1

Xavier T.
Xavier T.

Reputation: 42218

nnoremap <D-s> :wa in your .vimrc should do the trick.

nnoremap means this mapping is only available in Normal mode, and is not recursive.

:wa means write all, i.e. save all the current open buffers.

If you don't want to use a new mapping, you can simply type :wa to achieve the same things, but this is a matter of preferences only.

Upvotes: 3

Related Questions