MacOS – How to specify a startup folder in the open command to launch MacVim

command linemacosterminal

If I want to open a file in MacVim from the terminal. I use the following the command open -a MacVim --args filepath.

It disregards my working dir so I need to always specify the full path when opening a file. When I do open -a MacVim --args piano.py it assumes the file is in $HOME no matter what is my $PWD.

It is just an example. It applies to any application. Macos seems to not have the "Startup Folder" or "Start in" feature for executables in Windows.

I took a look in the mvim implementation.

 # Note: this isn't perfect, because any error output goes to the
 # terminal instead of the console log.
 # But if you use open instead, you will need to fully qualify the
 # path names for any filenames you specify, which is hard.
 exec "$binary" -g $opts ${1:+"$@"}

Can I get MacVim to accept a startup path?

Best Answer

Since you're using MacVim, and it doesn't seem to be a problem with the open command:

MacVim comes with its own script called mvim.

You can use it just like gvim to open files in the MacVim GUI, or pass -v to it to open in regular text mode with the ability to use :gui later.


Also, you can just use open -a MacVim <file>, no need to use --args. It'll figure it out just as if you double-clicked on the file in the Finder.