Starting MacVim from the command line?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Starting MacVim from the command line?

Nico Weber-3

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

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Starting MacVim from the command line?

Björn Winckler
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

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

/Björn


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Starting MacVim from the command line?

Dave Land

On Aug 13, 2007, at 2:31 AM, björn wrote:

> 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
>
> In the readme I suggest the following alias
>   alias gvim=MacVim.app /Contents/MacOS/Vim -g
> does that not work for you?

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

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Starting MacVim from the command line?

Björn Winckler
In reply to this post by Björn Winckler
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

In the readme I suggest the following alias
  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


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Starting MacVim from the command line?

Nico Weber-3
In reply to this post by Björn Winckler

> 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



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Starting MacVim from the command line?

Björn Winckler
> 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
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Starting MacVim from the command line?

Nico Weber-3
In reply to this post by Björn Winckler

> 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.


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Starting MacVim from the command line?

Nico Weber-3
In reply to this post by Björn Winckler

> 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"


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Starting MacVim from the command line?

Björn Winckler
> 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"

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

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---