Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I close MacVim using the standard vim command :q, the MacVim window closes, but the program is still running. This causes trouble when other processes try to spawn an instance of MacVim, because if it is still running, a special flag needs to be passed to MacVim so that a new instance is opened, but then the instances accumulate.

Is there a way using vimscript to kill the process as well as close the window upon exit?

share|improve this question
add comment

1 Answer

If you consistently end up with multiple MacVim icons in your Dock, then you might want to examine how you are starting MacVim. Specifically, :help macvim-start says

Do NOT call the MacVim binary inside the app bundle to start MacVim.

From the command line, you would normally use either open -a MacVim filename or mvim filename1. From the GUI, you can associate MacVim with particular extensions, drag-and-drop files onto MacVim in Finder or the Dock or into an open MacVim window, or you can use the Services menu to start new buffers with selections from other applications. There is also the mvim:// URL handler (see :help mvim://).

None of these methods require any special flags/options whether an existing instance is running or not and should ever create an extra MacVim icon in the Dock.

1 mvim is a script that comes with MacVim; see :help mvim. Once you have it installed in a directory in your PATH, then you can use it to edit files in an existing MacVim instance (or will launch one if it was not already running).


The “After last window closes:” Quit MacVim option in the General tab of MacVim’s preferences (⌘, or MacVim > Preferences…) may be what you want.

If you really need something more specific, then you can use the MacVim-custom command :macaction terminate: to ask the whole MacVim application to exit at any scriptable moment. It should be equivalent to ⌘Q and the MacVim > Quit MacVim menu item (they all send the terminate: action to the application’s first responder); if you have modified buffers, then it will ask you if you want to “Quit anyway?”.

It sounds like you might want to hook it up to the VimLeave event through an autocommand:

autocmd VimLeave * macaction terminate:
share|improve this answer
    
Thank you, that is exactly what I was looking for. –  Tobi Lehman Jul 19 '11 at 20:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.