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

map with empty yank

Expand Messages
  • Carlos Pita
    Hi all, I would like to yank the inner contents of or (...) expressions in a mapping. In normal mode I can try with the two-yank sequence yi
    Message 1 of 7 , Jan 28 11:36 AM
      Hi all,

      I would like to yank the inner contents of <...> or (...) expressions in a mapping. In normal mode I can try with the two-yank sequence yi<yi(. One of the yanks will be empty and the other will match the desired contents. The net effect is to match the contents no matter they were inside () or <>. Now if I put that in a map it seems to abort when the first yank fails, so it only matches the contents for <...> expressions (because yi< is the first probed yank). If I put :normal yi<<CR>:normal yi( instead, the mapping works the same than when I manually type it in normal mode. The E flag is not included in my cpoptions.

      Could someone clarify this behavior, please?

      Best regards
      --
      Carlos

      --
      --
      You received this message from the "vim_use" 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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Carlos Pita
      PD: I m assuming and (...) expressions are not nested, of course. ... -- -- You received this message from the vim_use maillist. Do not top-post! Type
      Message 2 of 7 , Jan 28 11:39 AM
        PD: I'm assuming <...> and (...) expressions are not nested, of course.

        On Tuesday, January 28, 2014 4:36:49 PM UTC-3, Carlos Pita wrote:
        > Hi all,
        >
        > I would like to yank the inner contents of <...> or (...) expressions in a mapping. In normal mode I can try with the two-yank sequence yi<yi(. One of the yanks will be empty and the other will match the desired contents. The net effect is to match the contents no matter they were inside () or <>. Now if I put that in a map it seems to abort when the first yank fails, so it only matches the contents for <...> expressions (because yi< is the first probed yank). If I put :normal yi<<CR>:normal yi( instead, the mapping works the same than when I manually type it in normal mode. The E flag is not included in my cpoptions.
        >
        > Could someone clarify this behavior, please?
        >
        > Best regards
        > --
        > Carlos

        --
        --
        You received this message from the "vim_use" 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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Christian Brabandt
        Hi Carlos! ... That is explained (although only briefly) at :h map-error I am not sure, there is an easy way to achieve what you want. I think, something like
        Message 3 of 7 , Jan 28 12:06 PM
          Hi Carlos!

          On Di, 28 Jan 2014, Carlos Pita wrote:

          > I would like to yank the inner contents of <...> or (...) expressions
          > in a mapping. In normal mode I can try with the two-yank sequence
          > yi<yi(. One of the yanks will be empty and the other will match the
          > desired contents. The net effect is to match the contents no matter
          > they were inside () or <>. Now if I put that in a map it seems to
          > abort when the first yank fails, so it only matches the contents for
          > <...> expressions (because yi< is the first probed yank). If I put
          > :normal yi<<CR>:normal yi( instead, the mapping works the same than
          > when I manually type it in normal mode. The E flag is not included in
          > my cpoptions.
          >
          > Could someone clarify this behavior, please?

          That is explained (although only briefly) at :h map-error

          I am not sure, there is an easy way to achieve what you want. I think,
          something like this could work:

          fu! MapAngle()
          if searchpairpos('<', '', '>', 'bn') ==# [0,0]
          return "i("
          else
          return "i<"
          endif
          endfu

          omap <expr> i_ MapAngle()


          Best,
          Christian
          --
          "But Huey, you PROMISED!"
          "Tell 'em I lied."

          --
          --
          You received this message from the "vim_use" 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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Carlos Pita
          Hi Christian, thanks for your prompt reply! It s still not clear to me whether yanking a non-existent text object always raises an error or not. cpoptions E
          Message 4 of 7 , Jan 28 12:15 PM
            Hi Christian,

            thanks for your prompt reply! It's still not clear to me whether
            yanking a non-existent text object always raises an error or not.
            cpoptions E seems to apply to y<motion> but it's not clearly stated
            (at least, I can't find that statement) what happens with y<object>.

            There is an easy workaround that I mentioned before: :norm
            yi<<CR>:norm yi(<CR>. It's somewhat hackish but it's concise. It
            should be noticed that :norm yi<yi( also fails. This last observation
            reinforces the "y<object> always raises an error for non-matched
            objects" theory.

            Best regards
            --
            Carlos



            On Tue, Jan 28, 2014 at 5:06 PM, Christian Brabandt <cblists@...> wrote:
            > Hi Carlos!
            >
            > On Di, 28 Jan 2014, Carlos Pita wrote:
            >
            >> I would like to yank the inner contents of <...> or (...) expressions
            >> in a mapping. In normal mode I can try with the two-yank sequence
            >> yi<yi(. One of the yanks will be empty and the other will match the
            >> desired contents. The net effect is to match the contents no matter
            >> they were inside () or <>. Now if I put that in a map it seems to
            >> abort when the first yank fails, so it only matches the contents for
            >> <...> expressions (because yi< is the first probed yank). If I put
            >> :normal yi<<CR>:normal yi( instead, the mapping works the same than
            >> when I manually type it in normal mode. The E flag is not included in
            >> my cpoptions.
            >>
            >> Could someone clarify this behavior, please?
            >
            > That is explained (although only briefly) at :h map-error
            >
            > I am not sure, there is an easy way to achieve what you want. I think,
            > something like this could work:
            >
            > fu! MapAngle()
            > if searchpairpos('<', '', '>', 'bn') ==# [0,0]
            > return "i("
            > else
            > return "i<"
            > endif
            > endfu
            >
            > omap <expr> i_ MapAngle()
            >
            >
            > Best,
            > Christian
            > --
            > "But Huey, you PROMISED!"
            > "Tell 'em I lied."
            >
            > --
            > --
            > You received this message from the "vim_use" 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
            >
            > ---
            > You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
            > To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/nBBm61o00pI/unsubscribe.
            > To unsubscribe from this group and all its topics, send an email to vim_use+unsubscribe@....
            > For more options, visit https://groups.google.com/groups/opt_out.

            --
            --
            You received this message from the "vim_use" 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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Christian Brabandt
            ... I think, there is no such thing as an empty text object. If the text object isn t valid, Vim raises an error and this also happens in normal mode (you can
            Message 5 of 7 , Jan 28 12:41 PM
              On Di, 28 Jan 2014, Carlos Pita wrote:
              > thanks for your prompt reply! It's still not clear to me whether
              > yanking a non-existent text object always raises an error or not.
              > cpoptions E seems to apply to y<motion> but it's not clearly stated
              > (at least, I can't find that statement) what happens with y<object>.

              I think, there is no such thing as an empty text object. If the text
              object isn't valid, Vim raises an error and this also happens in normal
              mode (you can see, by :set visualbell and see how the terminal flashes
              when doing yi< and the cursor not being within a <> pair.

              This errors causes, that your mapping will be aborted.

              Best,
              Christian
              --
              I disagree with what you say, but will defend to the death your right to
              tell such LIES!

              --
              --
              You received this message from the "vim_use" 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

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Carlos Pita
              For future reference, I m quoting here what a guy in stackoverflow suggested: Note that the semantics of :normal changes when it is contained in a try...catch
              Message 6 of 7 , Jan 28 12:47 PM
                For future reference, I'm quoting here what a guy in stackoverflow suggested:

                Note that the semantics of :normal changes when it is contained in a
                try...catch loop, or executed through :silent!: Without it, execution
                of the command sequence aborts when an error is encountered; the rest
                of the sequence is discarded (like in a macro). With it, all commands
                execute, even if an error occurs.

                Therefore, you can get the desired behavior with

                :silent! normal! yi<yi(

                Seems a bit cleaner to me than calling :normal twice.

                Regards (and thank you again, Christian)
                --
                Carlos



                On Tue, Jan 28, 2014 at 5:41 PM, Christian Brabandt <cblists@...> wrote:
                >
                > On Di, 28 Jan 2014, Carlos Pita wrote:
                >> thanks for your prompt reply! It's still not clear to me whether
                >> yanking a non-existent text object always raises an error or not.
                >> cpoptions E seems to apply to y<motion> but it's not clearly stated
                >> (at least, I can't find that statement) what happens with y<object>.
                >
                > I think, there is no such thing as an empty text object. If the text
                > object isn't valid, Vim raises an error and this also happens in normal
                > mode (you can see, by :set visualbell and see how the terminal flashes
                > when doing yi< and the cursor not being within a <> pair.
                >
                > This errors causes, that your mapping will be aborted.
                >
                > Best,
                > Christian
                > --
                > I disagree with what you say, but will defend to the death your right to
                > tell such LIES!
                >
                > --
                > --
                > You received this message from the "vim_use" 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
                >
                > ---
                > You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
                > To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/nBBm61o00pI/unsubscribe.
                > To unsubscribe from this group and all its topics, send an email to vim_use+unsubscribe@....
                > For more options, visit https://groups.google.com/groups/opt_out.

                --
                --
                You received this message from the "vim_use" 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

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • ZyX
                ... If this works inside `:try` then it is a bug. Though I am unable to reproduce it. `:silent!` variant is documented. -- -- You received this message from
                Message 7 of 7 , Jan 28 12:59 PM
                  On Wednesday, January 29, 2014 12:47:01 AM UTC+4, Carlos Pita wrote:
                  > For future reference, I'm quoting here what a guy in stackoverflow suggested:
                  >
                  >
                  > Note that the semantics of :normal changes when it is contained in a
                  > try...catch loop, or executed through :silent!: Without it, execution
                  > of the command sequence aborts when an error is encountered; the rest
                  > of the sequence is discarded (like in a macro). With it, all commands
                  > execute, even if an error occurs.
                  >
                  > Therefore, you can get the desired behavior with
                  >
                  > :silent! normal! yi<yi(
                  >
                  > Seems a bit cleaner to me than calling :normal twice.

                  If this works inside `:try` then it is a bug. Though I am unable to reproduce it. `:silent!` variant is documented.

                  --
                  --
                  You received this message from the "vim_use" 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

                  ---
                  You received this message because you are subscribed to the Google Groups "vim_use" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                Your message has been successfully submitted and would be delivered to recipients shortly.