0

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?

  • Just played around with it a bit myself. It seems to work if MacVim is not running, but it doesn't open a new file/window into an already running MacVim. – nohillside Nov 4 '18 at 13:03
  • I dokillall before. It does work, but the problem is that the paths can't be relative to the current dir. Maybe I should have formulated it otherwise. – eyal karni Nov 4 '18 at 15:30
  • Then do :-) I don‘t think it‘s an issue with open though (because it works with relative paths if MacVim is not running). – nohillside Nov 4 '18 at 16:02
  • If you're using MacVim, you can also use their mvim script, which acts like the gvim command. – SilverWolf Nov 4 '18 at 16:58
  • It doesn't work with relative paths is MacVim is not running. It tries to open the same file on /Users/username/ – eyal karni Nov 4 '18 at 19:40
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .