Loading ...
Sorry, an error occurred while loading the content.

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

Expand Messages
  • 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,
    Message 1 of 8 , Mar 18, 2008
    • 0 Attachment
      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
      -~----------~----~----~----~------~----~------~--~---
    • Ben Schmidt
      ... 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
      Message 2 of 8 , Mar 18, 2008
      • 0 Attachment
        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
        -~----------~----~----~----~------~----~------~--~---
      • travis
        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? ...
        Message 3 of 8 , Mar 18, 2008
        • 0 Attachment
          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 <mrie...@...> 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
          -~----------~----~----~----~------~----~------~--~---
        • Timothy Knox
          ... 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
          Message 4 of 8 , Mar 18, 2008
          • 0 Attachment
            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:tdk@...>
            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
            -~----------~----~----~----~------~----~------~--~---
          • Nico Weber
            ... set editor = mvim -f should work, shouldn t it? At least `export EDITOR= mvim -f ` works for git and svn. Nico
            Message 5 of 8 , Mar 18, 2008
            • 0 Attachment
              >> 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
              -~----------~----~----~----~------~----~------~--~---
            • Ben Schmidt
              ... Yes, I think so. Or editor= mvim --remote-tab-wait I wonder where my earlier post that suggested those two things went. Ben.
              Message 6 of 8 , Mar 19, 2008
              • 0 Attachment
                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
                -~----------~----~----~----~------~----~------~--~---
              • Cyclify
                Ben and Nico, Thanks for your reply! mvim --remote-tab-wait is exactly the functionality that I need. --Marc ...
                Message 7 of 8 , Mar 19, 2008
                • 0 Attachment
                  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 <mail_ben_schm...@...> 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
                  -~----------~----~----~----~------~----~------~--~---
                • John_108
                  ... 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
                  Message 8 of 8 , Apr 13, 2012
                  • 0 Attachment
                    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
                  Your message has been successfully submitted and would be delivered to recipients shortly.