Quantcast

"Edit in External Editor..." feature from the command line (or from mutt)

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

"Edit in External Editor..." feature from the command line (or from mutt)

Cyclify

The "Edit in External Editor..." feature is great. I would like to
have the same functionality from the command line (specifically, from
my email client, mutt). Can you suggest how this might be done?

The standard approach is to call Vi in the terminal. However, I would
like to edit all my files in MacVim. I can't simply issue an "open -a
MacVim" command since this returns; the call must be a blocking one.
Perhaps one of the scripts (gvim) blocks?

Ideally, I would like the call to open the file in a buffer in a new
tab in an existing window of MacVim, and to return once I've deleted
the buffer. Should this be done with the remote client/server
functionality?

Currently I have this working, through the following route: I call a
script instead of MacVim. The script creates a lock file, calls
MacVim, and then waits for the lock file to be removed. When I'm done
editing the file, I issue a command in Vim that writes the file,
deletes the buffer and removes the lock file. The script and the
function are copied below.

My solution works, but I'm wondering if there's a more direct route --
one that doesn't write lock files. Any thoughts or comments would be
appreciated.

Kudos for doing such a great job with MacVim.

--Marc


Script that creates a lock file, calls MacVim, and then waits for the
lock file to be removed:

#! /bin/tcsh

if !(-f $1) touch $1
touch $1.lck
open -a MacVim $1
while (-f $1.lck)
    sleep 0.1
end

Vim function that writes the file, deletes the buffer, and then
removes the lock file:

function! <SID>WriteDeleteUnlock()
   let l:lockfile = expand("%:p").'.lck'
   write
   execute("bdelete")
   call system("rm -f ".l:lockfile)
endfunction
--~--~---------~--~----~------------~-------~--~----~
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
|  
Report Content as Inappropriate
star

Re: "Edit in External Editor..." feature from the command line (or from mutt)

Ben Schmidt

Cyclify wrote:
> The "Edit in External Editor..." feature is great. I would like to
> have the same functionality from the command line (specifically, from
> my email client, mutt). Can you suggest how this might be done?
>
> The standard approach is to call Vi in the terminal. However, I would
> like to edit all my files in MacVim. I can't simply issue an "open -a
> MacVim" command since this returns; the call must be a blocking one.
> Perhaps one of the scripts (gvim) blocks?

I think you should be able to do

/Applications/MacVim.app/Contents/MacOS/Vim -f "$1"

or similar, using the mvim script included with MacVim. It will open a Vim
instance (MacVim window) but remain in the foreground (block) until that window is
closed (and thus the corresponding Vim instance exits).

> Ideally, I would like the call to open the file in a buffer in a new
> tab in an existing window of MacVim, and to return once I've deleted
> the buffer. Should this be done with the remote client/server
> functionality?

The --remote-tab-wait Vim option is for precisely this, I believe, so something like

/Applications/MacVim.app/Contents/MacOS/Vim --remote-tab-wait "$1"

or with the mvim script.

See :help --remote-tab-wait

Ben.



--~--~---------~--~----~------------~-------~--~----~
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
|  
Report Content as Inappropriate
star

Re: "Edit in External Editor..." feature from the command line (or from mutt)

travis jeffery
In reply to this post by Cyclify

In your .muttrc file just do 'set editor = mvim'
and call MacVim in the terminal by mvim, is that too simple or am I
missing something?

On Mar 18, 7:37 pm, Cyclify <[hidden email]> wrote:

> The "Edit in External Editor..." feature is great. I would like to
> have the same functionality from the command line (specifically, from
> my email client, mutt). Can you suggest how this might be done?
>
> The standard approach is to call Vi in the terminal. However, I would
> like to edit all my files in MacVim. I can't simply issue an "open -a
> MacVim" command since this returns; the call must be a blocking one.
> Perhaps one of the scripts (gvim) blocks?
>
> Ideally, I would like the call to open the file in a buffer in a new
> tab in an existing window of MacVim, and to return once I've deleted
> the buffer. Should this be done with the remote client/server
> functionality?
>
> Currently I have this working, through the following route: I call a
> script instead of MacVim. The script creates a lock file, calls
> MacVim, and then waits for the lock file to be removed. When I'm done
> editing the file, I issue a command in Vim that writes the file,
> deletes the buffer and removes the lock file. The script and the
> function are copied below.
>
> My solution works, but I'm wondering if there's a more direct route --
> one that doesn't write lock files. Any thoughts or comments would be
> appreciated.
>
> Kudos for doing such a great job with MacVim.
>
> --Marc
>
> Script that creates a lock file, calls MacVim, and then waits for the
> lock file to be removed:
>
> #! /bin/tcsh
>
> if !(-f $1) touch $1
> touch $1.lck
> open -a MacVim $1
> while (-f $1.lck)
>     sleep 0.1
> end
>
> Vim function that writes the file, deletes the buffer, and then
> removes the lock file:
>
> function! <SID>WriteDeleteUnlock()
>    let l:lockfile = expand("%:p").'.lck'
>    write
>    execute("bdelete")
>    call system("rm -f ".l:lockfile)
> endfunction
--~--~---------~--~----~------------~-------~--~----~
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
|  
Report Content as Inappropriate
star

Re: "Edit in External Editor..." feature from the command line (or from mutt)

Timothy Knox

Somewhere on Shadow Earth, at Tue, Mar 18, 2008 at 06:28:29PM -0700, travis wrote:
>
> In your .muttrc file just do 'set editor = mvim'
> and call MacVim in the terminal by mvim, is that too simple or am I
> missing something?

Yes, unfortunately, you are. mutt (and many other Unix-y programs that support
an external editor) need the editor to not exit until the edit is done. For
example, I use mutt and vim to process my mail, and I have gvim wrapped in a
shell script called gvimf, that just does a 'gvim -f "$@"' so that it will stick
around until I am done, then return the edited file to mutt to send.

--
Timothy Knox <mailto:[hidden email]>
The one thing I've learned about freedom of expression is that you really
ought to keep that sort of thing to yourself.
    -- Scott Adams, _I'm Not Anti-Business, I'm Anti-Idiot_

--~--~---------~--~----~------------~-------~--~----~
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
|  
Report Content as Inappropriate
star

Re: "Edit in External Editor..." feature from the command line (or from mutt)

Nico Weber-3

>> In your .muttrc file just do 'set editor = mvim'
>> and call MacVim in the terminal by mvim, is that too simple or am I
>> missing something?
>
> Yes, unfortunately, you are. mutt (and many other Unix-y programs  
> that support
> an external editor) need the editor to not exit until the edit is  
> done. For
> example, I use mutt and vim to process my mail, and I have gvim  
> wrapped in a
> shell script called gvimf, that just does a 'gvim -f "$@"' so that  
> it will stick
> around until I am done, then return the edited file to mutt to send.

     set editor ="mvim -f"

should work, shouldn't it? At least `export EDITOR="mvim -f"` works  
for git and svn.

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
|  
Report Content as Inappropriate
star

Re: "Edit in External Editor..." feature from the command line (or from mutt)

Ben Schmidt

Nico Weber wrote:

>>> In your .muttrc file just do 'set editor = mvim'
>>> and call MacVim in the terminal by mvim, is that too simple or am I
>>> missing something?
>> Yes, unfortunately, you are. mutt (and many other Unix-y programs  
>> that support
>> an external editor) need the editor to not exit until the edit is  
>> done. For
>> example, I use mutt and vim to process my mail, and I have gvim  
>> wrapped in a
>> shell script called gvimf, that just does a 'gvim -f "$@"' so that  
>> it will stick
>> around until I am done, then return the edited file to mutt to send.
>
>      set editor ="mvim -f"
>
> should work, shouldn't it? At least `export EDITOR="mvim -f"` works  
> for git and svn.

Yes, I think so. Or

editor="mvim --remote-tab-wait"

I wonder where my earlier post that suggested those two things went.

Ben.



--~--~---------~--~----~------------~-------~--~----~
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
|  
Report Content as Inappropriate
star

Re: "Edit in External Editor..." feature from the command line (or from mutt)

Cyclify

Ben and Nico,

Thanks for your reply!

"mvim --remote-tab-wait" is exactly the functionality that I need.

--Marc

On Mar 19, 8:35 am, Ben Schmidt <[hidden email]> wrote:

> Nico Weber wrote:
> >>> In your .muttrc file just do 'set editor = mvim'
> >>> and call MacVim in the terminal by mvim, is that too simple or am I
> >>> missing something?
> >> Yes, unfortunately, you are. mutt (and many other Unix-y programs  
> >> that support
> >> an external editor) need the editor to not exit until the edit is  
> >> done. For
> >> example, I use mutt and vim to process my mail, and I have gvim  
> >> wrapped in a
> >> shell script called gvimf, that just does a 'gvim -f "$@"' so that  
> >> it will stick
> >> around until I am done, then return the edited file to mutt to send.
>
> >      set editor ="mvim -f"
>
> > should work, shouldn't it? At least `export EDITOR="mvim -f"` works  
> > for git and svn.
>
> Yes, I think so. Or
>
> editor="mvim --remote-tab-wait"
>
> I wonder where my earlier post that suggested those two things went.
>
> Ben.
--~--~---------~--~----~------------~-------~--~----~
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
|  
Report Content as Inappropriate
star

Re: "Edit in External Editor..." feature from the command line (or from mutt)

John_108
In reply to this post by Nico Weber-3
This worked great for me:
 
>      set editor ="mvim -f"

except that after writing the file and closing MacVim, I had to switch back to the terminal to get back to mutt.

In the current MacVim version 7.3.390 (and maybe for much longer) the solution is found in "help: hints":

 mvim -f -c "au VimLeave * maca hide:

Works like a charm. When I start to compose in Mutt, MacVim opens, and when I finish the focus returns to mutt automatically.

--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Loading...