Vim Tips Wiki

Open files in same window under Mac OS X

Redirected from VimTip1500

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 1500 Printable Monobook Previous Next

created February 1, 2007 · complexity intermediate · version 6.0

This tip shows you how to open files from the command line in the same window (Vim instance), using applescript. The applescript is specific to

Create a file called gvim.scpt (for example) with the following applescript code:

on run argv
   tell application "Vim"
      repeat with n from 1 to (count of argv)
         set theUnixPath to item n of argv
         set theMacPath to (POSIX file theUnixPath) as string
         open file theMacPath
      end repeat
   end tell
end run

This applescript tells a running to open each argument in a new buffer. The script can be invoked with the 'osascript' command ('man osascript' for details): a good way to do this is to create a shell script somewhere in your path:

osascript /path/to/gvim.scpt $*

What this doesn't do yet: Create the files automatically if they do not exist. In fact the script will fail and complain if you pass the name of a file that doesn't exist, and any following files also won't be opened.


see this page for doing this with the new mac vim

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki