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

Re: run macro only in visual mode

Expand Messages
  • Tobias Reif
    ... Well, that runs the whole buffer. Tobi -- http://www.pinkjuice.com/
    Message 1 of 10 , Jun 3, 2002
      Luc Hermitte wrote:


      > vmap r <esc>:w !ruby<cr>


      Well, that runs the whole buffer.

      Tobi

      --
      http://www.pinkjuice.com/
    • Tobias Reif
      ... BTW, the gv tip was helpful :) Tobi -- http://www.pinkjuice.com/
      Message 2 of 10 , Jun 3, 2002
        > Luc Hermitte wrote:


        BTW, the gv tip was helpful :)


        Tobi


        --
        http://www.pinkjuice.com/
      • Tobias Reif
        Benji Fisher wrote: [vmap] thanks :) (more below) ... That s what I thought is great, since
        Message 3 of 10 , Jun 3, 2002
          Benji Fisher wrote:

          [vmap]

          thanks :)
          (more below)


          > That's right. All Command-mode commands (a.k.a. Ex commands, colon
          > commands) are line-oriented, and vim conveniently inserts the Visual
          > marks when you enter Command mode from any of the Visual modes.


          That's what I thought is great, since

          "'< `< To the first character of the last selected Visual
          area in the current buffer. {not in Vi}.

          '> `> To the last character of the last selected Visual
          area in the current buffer. {not in Vi}."

          This tells me that if GVim kindly inserts '<,'>, the range which I send
          is the selection, not the whole line. Hmm...

          > You can
          > do something like
          >
          > :vmap r y:echo @"<CR>
          >
          > to echo the current Visual selection (not necesarily whole lines).
          > Maybe something similar can be used to send it to ruby.


          I could send the yanked string via
          ruby -e
          (eval), like
          vmap ;r y:!ruby -e 'echo @"'<CR>gv

          but this issues
          ruby -e 'echo @"'
          ; how to expand @" ?

          Tobi

          --
          http://www.pinkjuice.com/
        • Benji Fisher
          ... [snip] ... Still untested, but try ... Try it first with a one-line ruby command. I am not sure how new lines will be translated; you may have to play
          Message 4 of 10 , Jun 3, 2002
            Tobias Reif wrote:
            >
            > Benji Fisher wrote:
            >
            [snip]
            > > You can
            > > do something like
            > >
            > > :vmap r y:echo @"<CR>
            > >
            > > to echo the current Visual selection (not necesarily whole lines).
            > > Maybe something similar can be used to send it to ruby.
            >
            > I could send the yanked string via
            > ruby -e
            > (eval), like
            > vmap ;r y:!ruby -e 'echo @"'<CR>gv
            >
            > but this issues
            > ruby -e 'echo @"'
            > ; how to expand @" ?

            Still untested, but try

            :vmap ;r y:execute "!ruby -e 'echo " . @" ."'"<CR>gv

            Try it first with a one-line ruby command. I am not sure how new lines will
            be translated; you may have to play around with substitute(@", ...) to get it
            to work.

            HTH --Benji Fisher
          • Tobias Reif
            ... One step further, thanks :) It brings ruby -e echo puts 999 on the console, instead of ruby -e puts 999 Also, I will have to escape quotes, as in ruby
            Message 5 of 10 , Jun 3, 2002
              Benji Fisher wrote:


              > :vmap ;r y:execute "!ruby -e 'echo " . @" ."'"<CR>gv


              One step further, thanks :)

              It brings
              ruby -e 'echo puts 999'
              on the console, instead of
              ruby -e 'puts 999'

              Also, I will have to escape quotes, as in
              ruby -e "puts \"foo\""

              Update:
              This
              :vmap ;r y:execute "!ruby -e '" . @" ."'"<CR>gv
              works :)

              I'll play with the escaping tomorrow... thanks again!

              Tobi

              --
              http://www.pinkjuice.com/
            • Preben Peppe Guldberg
              ... Note that this may not be entirely correct. The exception is visual blockwise mode, where ` and `
              Message 6 of 10 , Jun 4, 2002
                Thus wrote Tobias Reif (tobiasreif@...) on [020603]:

                > "'< `< To the first character of the last selected Visual
                > area in the current buffer. {not in Vi}.

                > '> `> To the last character of the last selected Visual
                > area in the current buffer. {not in Vi}."

                Note that this may not be entirely correct.

                The exception is visual blockwise mode, where `> and `< may point to the
                upper right and lower left corner, respectively. This happens if the
                starting point for the visual selection is the upper right or lower left
                corner.

                Peppe
                --
                "Before you criticize someone, walk
                Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
                c928400@... (o o) he gets angry, he'll be a mile away
                ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
              • Tobias Reif
                ... Sure; but it was simply qoted from :h
                Message 7 of 10 , Jun 4, 2002
                  Preben Peppe Guldberg wrote:


                  > Note that this may not be entirely correct.
                  >
                  > The exception is visual blockwise mode, where `> and `< may point to the
                  > upper right and lower left corner, respectively. This happens if the
                  > starting point for the visual selection is the upper right or lower left
                  > corner.


                  Sure; but it was simply qoted from :h '< :

                  "
                  *'<* *`<*
                  '< `< To the first character of the last selected Visual
                  area in the current buffer. {not in Vi}.

                  *'>* *`>*
                  '> `> To the last character of the last selected Visual
                  area in the current buffer. {not in Vi}.
                  "

                  I also can not see how this is relevant to my complaint.

                  Do ctrl-v, then move until you get a selected block, do "+y; you get a
                  string you can paste into other programs. This is the string on which
                  :w, :s///, etc should work, as does y etc. Instead, :s for example works
                  on all involved lines, as whole lines, unfortunately.


                  Tobi


                  --
                  http://www.pinkjuice.com/
                Your message has been successfully submitted and would be delivered to recipients shortly.