Starting MacVim from the command line?

272 views
Skip to first unread message

Nico Weber

unread,
Aug 13, 2007, 5:27:05 AM8/13/07
to vim mac
Hi,

is there a way to start MacVim from the command line? I usually start
gvim from Terminal.app; usually with several flags. Simplest use case
is `gvim filename` which works by symlinking gvim to MacVim.app/
Contents/MacOS/MacVim, but only if 'filename' already exists.
Furthermore, I often do `gvim -S session.vim` to launch vim with a
set of files. This doesn't seem to work at all.

It'd be great if there was some kind of shell script that opens a new
MacVim window and passes all parameters to the Vim instance that
belongs to that window. Is there something like that? If not, how
would I write something like that?

Thanks,
Nico

björn

unread,
Aug 13, 2007, 5:31:20 AM8/13/07
to vim...@googlegroups.com

In the readme I suggest the following alias
  alias gvim=MacVim.app /Contents/MacOS/Vim -g
does that not work for you?

/Björn

björn

unread,
Aug 13, 2007, 5:40:48 AM8/13/07
to vim...@googlegroups.com
  alias gvim= MacVim.app /Contents/MacOS/Vim -g

does that not work for you?

For the record, the alias should contain the entire path to MacVim.app.  So assuming MacVim.app is in your /Applications folder, the alias should be:
  alias gvim=/Applications/MacVim.app/Contents/MacOS/Vim -g
Sorry about that.


/Björn

Nico Weber

unread,
Aug 13, 2007, 5:48:55 AM8/13/07
to vim...@googlegroups.com
> In the readme I suggest the following alias
> alias gvim=MacVim.app /Contents/MacOS/Vim -g
> does that not work for you?

Bah, readme files :-P Kinda works (modulo whitespace escaping ("..Vim
\ -g"), but I have a session file that doesn't finish loading until I
hit some keys (doesn't work if I load the session with the toolbar
button or `:source`, but works fine in carbon vim). "Doesn't finish
loading" means that nothing is drawn and that only two tabs are
displayed although the session contains five tabs. After I hit 'j',
everything is fine though.

Another small (unrelated) bug: Toggle the toolbar off, maximize the
window, toggle toolbar back on -- now the first few lines are drawn
below the toolbar.

And a suggestion: Clicking the toolbar toggle button in the upper
right corner should update the 't' flag in guioptions (without that,
clicking the button to hide the toolbar and doing 'set guioptions+=t'
doesn't work for example).

Nico


björn

unread,
Aug 13, 2007, 6:01:23 AM8/13/07
to vim...@googlegroups.com
> In the readme I suggest the following alias
>   alias gvim=MacVim.app /Contents/MacOS/Vim -g
> does that not work for you?

Bah, readme files :-P Kinda works (modulo whitespace escaping ("..Vim
\ -g"), but I have a session file that doesn't finish loading until I
hit some keys (doesn't work if I load the session with the toolbar
button or `:source`, but works fine in carbon vim). "Doesn't finish
loading" means that nothing is drawn and that only two tabs are
displayed although the session contains five tabs. After I hit 'j',
everything is fine though.

Sounds like the command queue in MMBackend does not get flushed after loading the session file.  I'll look into it.

I'm not entirely sure what you mean by "modulo whitespace escaping"...the arguments you specify go straight to main in vim7/src/main.c.  Do you have these problems if you start without the -g switch?

Another small (unrelated) bug: Toggle the toolbar off, maximize the
window, toggle toolbar back on -- now the first few lines are drawn
below the toolbar.

Thanks, I'll look into this as well.

And a suggestion: Clicking the toolbar toggle button in the upper
right corner should update the 't' flag in guioptions (without that,
clicking the button to hide the toolbar and doing 'set guioptions+=t'
doesn't work for example).

Yes, that is a problem.  Cocoa gives you no chance to interact with the "pill button" (hide/show toolbar) so this has to be hacked.  I looked into something similar before so I can probably fix this.  Thanks for bringing it to my attention.


/Björn

Nico Weber

unread,
Aug 13, 2007, 6:02:17 AM8/13/07
to vim...@googlegroups.com
> For the record, the alias should contain the entire path to
> MacVim.app. So assuming MacVim.app is in your /Applications
> folder, the alias should be:
> alias gvim=/Applications/MacVim.app/Contents/MacOS/Vim -g

I think it's better to have a shell script file called 'gvim' or
'mvim' or whatever that contains the command above. That way, the vim
instance stays open if you close terminal.app. With the alias, macvim
closes when its parent shell is closed.

Nico Weber

unread,
Aug 13, 2007, 6:09:53 AM8/13/07
to vim...@googlegroups.com
> I'm not entirely sure what you mean by "modulo whitespace
> escaping"...the arguments you specify go straight to main in vim7/
> src/main.c. Do you have these problems if you start without the -g
> switch?

No, but bash needs it. If you do

alias bla=ls -l

you get

-bash: alias: -l: not found

You need

alias bla=ls\ -l

or

alias bla="ls -l"

björn

unread,
Aug 13, 2007, 6:17:43 AM8/13/07
to vim...@googlegroups.com

Ah! Of course...I forgot to add the quotes, the readme, which is correct, says:
  alias gvim='/Applications/MacVim.app/Contents/MacOS/Vim -g'

But I agree with you that a shell script might be a better idea.  If you have one, maybe you wouldn't mind sharing it?  I can upload it to the google code page if you email it to me.


/Björn

Dave Land

unread,
Aug 13, 2007, 4:38:50 AM8/13/07
to vim...@googlegroups.com

Mac OS X has a well-documented command "open" that is specifically
designed for launching Mac OS X applications from the command line:

open -a /Applications/MacVim.app file.txt

The downside is that it doesn't allow you to specify vim command-line
options, so I don't use it. It's fine for opening files with the
default options (open one or more files into buffers, with the first
file's buffer active on open).

As a result, I use a variation on Björn's suggestion: In general, I
find that bash functions work better than aliases because they allow
you to use several distinct command-line parameters. Thus:

function gvim { /Applications/MacVim.app/Contents/MacOS/Vim -g $*; }

With that function, you can specify Vim command-line parameters as well
as any file(s) to be edited:

gvim -d firstfile.txt secondfile.txt

Also, I don't have any problem with vim quitting when I quit the
terminal session, but I also don't remember if I haven't done
something else to prevent that. YMMV.

Dave

Reply all
Reply to author
Forward
0 new messages