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

Remote commands?

Expand Messages
  • Sean DeNigris
    Is there an easy way to use mvim --remote... to execute commands in a running instance of MacVim? This is what I ve figured out so far from experimenting/docs
    Message 1 of 4 , Feb 6 8:06 PM
    • 0 Attachment
      Is there an easy way to use mvim --remote... to execute commands in a
      running instance of MacVim?

      This is what I've figured out so far from experimenting/docs
      * I can use --remote-send to type in the command
      * I can call a function that executes commands

      What I want to do is call a ruby method.

      What I am doing now is to add a function to my .vimrc like:
      function DoCommand(cmd)
      exe a:cmd
      endfunction

      So the usage would be like:

      If I have a ruby method:
      def delete_line(num)
      cb = VIM::Buffer.current
      cb.delete(1)
      end

      I could call it from the command line with:
      mvim --remote-expr "DoCommand('ruby delete_line(1)')" --servername
      VIM

      This works, but I was wondering if there was a way to do it directly
      from the command line (in a running instance of MacVim).

      Thanks!

      Sean DeNigris

      --
      You received this message from the "vim_mac" maillist.
      For more information, visit http://www.vim.org/maillist.php
    • björn
      ... Hi (again) Sean, Sorry for taking so long to reply to your posts. I think what you are looking for is the remote functions , see :h
      Message 2 of 4 , Feb 14 8:36 AM
      • 0 Attachment
        On 7 February 2010 05:06, Sean DeNigris wrote:
        > Is there an easy way to use mvim --remote... to execute commands in a
        > running instance of MacVim?
        >
        > This is what I've figured out so far from experimenting/docs
        > * I can use --remote-send to type in the command
        > * I can call a function that executes commands
        >
        > What I want to do is call a ruby method.
        >
        > What I am doing now is to add a function to my .vimrc like:
        > function DoCommand(cmd)
        >  exe a:cmd
        > endfunction
        >
        > So the usage would be like:
        >
        >  If I have a ruby method:
        >    def delete_line(num)
        >      cb = VIM::Buffer.current
        >      cb.delete(1)
        >    end
        >
        >  I could call it from the command line with:
        >    mvim --remote-expr "DoCommand('ruby delete_line(1)')" --servername
        > VIM
        >
        > This works, but I was wondering if there was a way to do it directly
        > from the command line (in a running instance of MacVim).
        >
        > Thanks!

        Hi (again) Sean,

        Sorry for taking so long to reply to your posts. I think what you are
        looking for is the "remote functions", see ":h remote.txt|/FUNCTIONS".
        If that's not it, then I suggest you ask on the vim_use mailing list.

        Björn

        --
        You received this message from the "vim_mac" maillist.
        For more information, visit http://www.vim.org/maillist.php
      • Sean DeNigris
        ... I ve been using remote, and thought there might be a better way, but after posting on vim_use, it seems the two options for remote commands are: 1. sending
        Message 3 of 4 , Feb 15 4:05 PM
        • 0 Attachment
          > Sorry for taking so long to reply to your posts.  I think what you are
          > looking for is the "remote functions", see ":h remote.txt|/FUNCTIONS".

          I've been using remote, and thought there might be a better way, but
          after posting on vim_use, it seems the two options for remote commands
          are:
          1. sending keys
          2. wrapping exe in a function and calling it with remote-expr

          Thanks!

          --
          You received this message from the "vim_mac" maillist.
          For more information, visit http://www.vim.org/maillist.php
        • Tony Mechelynck
          ... Ben Fritz gave you the following solution on vim_use: --remote-send :ruby delete_line(1) which I think is as economical ( as elegant as a math
          Message 4 of 4 , Apr 3, 2010
          • 0 Attachment
            On Feb 16, 2:05 am, Sean DeNigris <truste...@...> wrote:
            > > Sorry for taking so long to reply to your posts.  I think what you are
            > > looking for is the "remote functions", see ":h remote.txt|/FUNCTIONS".
            >
            > I've been using remote, and thought there might be a better way, but
            > after posting on vim_use, it seems the two options for remote commands
            > are:
            > 1. sending keys
            > 2. wrapping exe in a function and calling it with remote-expr
            >
            > Thanks!

            Ben Fritz gave you the following solution on vim_use:

            --remote-send ':ruby delete_line(1)<CR>'

            which I think is as economical ("as elegant" as a math teacher would
            say) as you could get. I might add that you would maybe want to test
            for Ruby support -- something like (untested):

            --remote-send ':if has("ruby") | exe "ruby_delete_line(1)" | else |
            echoerr "Sorry, no ruby" | endif<CR>'

            (all on one line, and with single quotes around the whole to force the
            Unix-like shell to pass the | as part of the parameter). I wrap the
            ruby statement in an exe so that Vim versions without ruby support
            would not try to parse it.

            However you could delete the first line more easily without calling
            ruby:

            --remote-send ':1d<CR>'

            (which is still an ex-command) or

            --remote-send ggdd

            In the latter case I think the quotes can be omitted since there are
            no embedded spaces and no risk of interpretation by the shell.


            Best regards,
            Tony.
            --
            "Hey! Who took the cork off my lunch??!"
            -- W. C. Fields

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

            To unsubscribe, reply using "remove me" as the subject.
          Your message has been successfully submitted and would be delivered to recipients shortly.