Command-W is a Vim plugin which aims to replace and enhance the default ⌘W shortcut behaviour in MacVim.
This plugin is aimed at MacVim users who prefer buffers rather than tabs. If you use tabs, this plugin is not for you and you should really do some soul searching.
My main gripe: the ⌘W shortcut in MacVim should close buffers, not windows!
Lets be honest, a window in Vim is not equivalent to a tab in say TextMate - the correct equivalent is of course the humble buffer!
Here's how I want ⌘W to work:
- Close the current buffer but keep the window open (which buffkill already solves with it's
- When I press ⌘W on the last listed* buffer, I want MacVim to close.
*A listed buffer is one that shows up when you type the
:buffers command. Usually this list only includes editable buffers, so read-only buffers like NERDTree won't show up in this list.
- Vim 7+
- buffkill - Allows you to close a buffer without closing a window.
First, make sure you have buffkill installed. Command-W will not function correctly without it.
Simply copy the
plugin directory into your
If you have Pathogen installed, just clone this repo into a subdirectory of your
.vim/bundle directory like so:
cd ~/.vim/bundle git clone git://github.com/nathanaelkane/vim-command-w.git
Vundle (my preferred method)
If you have Vundle installed, simply add the following to your
Then use the
:BundleInstall command to install the plugin.
Add the following to your
macmenu &File.Close key=<nop> nmap <D-w> :CommandW<CR> imap <D-w> <Esc>:CommandW<CR>
Now you can press ⌘W to close buffers (or to close Vim if you only have one open buffer).
You can manually use
:CommandW instead of
:BD if you use bufkill).