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

How to create a abbreviation that expand ".." to "->" correctly?

Expand Messages
  • Rainux
    I want when I typed $this..var in Vim, it can auto expand .. to - so I got $this- var , I ve tried the following command in Vim, but it can work
    Message 1 of 9 , Jul 31, 2007
    • 0 Attachment
      I want when I typed "$this..var" in Vim, it can auto expand ".." to
      "->" so I got "$this->var", I've tried the following command in Vim,
      but it can work correctly.

      :iab .. ->

      I've tried :help abbreviations, in map.txt it says there are 3 types
      of abbreviations, but no details to tell me how to create these types
      of abbreviations.


      --
      Best Regards

      Rainux

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Kurt Smith
      ... With this abbreviation, VIM looks for a non-keyword character (usually a s character, but other non-keyword chars work, too) after the .. to trigger the
      Message 2 of 9 , Jul 31, 2007
      • 0 Attachment
        On 7/31/07, Rainux <rainux@...> wrote:
        >
        > I want when I typed "$this..var" in Vim, it can auto expand ".." to
        > "->" so I got "$this->var", I've tried the following command in Vim,
        > but it can work correctly.
        >
        > :iab .. ->

        With this abbreviation, VIM looks for a non-keyword character (usually
        a \s character, but other non-keyword chars work, too) after the ".."
        to trigger the abbreviation substitution. See :h 'iskeyword'. If you
        type a k.w. character after the .. it doesn't kick in, hence
        $this..var won't trigger, since the "v" is a keyword char.

        You could use

        :inoremap .. ->

        which will always work so long as you type the two dots within a
        'timeout' period. See :help 'timeout'. If you'd like two dots next
        to each other, you'll need to type one dot, wait a 'timeout' period,
        and type the other.

        Maybe there is a better way; anyone else?

        HTH,

        Kurt

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        ... No, I think you ve hit it. There s always a balancing question between having the abbrev kick in when wanted and not kick in when not wanted . .. as an
        Message 3 of 9 , Jul 31, 2007
        • 0 Attachment
          Kurt Smith wrote:
          > On 7/31/07, Rainux <rainux@...> wrote:
          >> I want when I typed "$this..var" in Vim, it can auto expand ".." to
          >> "->" so I got "$this->var", I've tried the following command in Vim,
          >> but it can work correctly.
          >>
          >> :iab .. ->
          >
          > With this abbreviation, VIM looks for a non-keyword character (usually
          > a \s character, but other non-keyword chars work, too) after the ".."
          > to trigger the abbreviation substitution. See :h 'iskeyword'. If you
          > type a k.w. character after the .. it doesn't kick in, hence
          > $this..var won't trigger, since the "v" is a keyword char.
          >
          > You could use
          >
          > :inoremap .. ->
          >
          > which will always work so long as you type the two dots within a
          > 'timeout' period. See :help 'timeout'. If you'd like two dots next
          > to each other, you'll need to type one dot, wait a 'timeout' period,
          > and type the other.
          >
          > Maybe there is a better way; anyone else?
          >
          > HTH,
          >
          > Kurt

          No, I think you've hit it. There's always a balancing question between "having
          the abbrev kick in when wanted" and "not kick in when not wanted". .. as an
          {lhs} would, for instance, interfere with a comment ending in three dots...

          I used to have

          :noreabbrev -- —

          in one script I used for HTML writing but I commented it out today: it was
          kicking in too often, and interfering with <!-- comments -->

          I could work around it by using <dash><left><dash><right> but it was a hassle.
          Writing out the entity (which I happen to have memorized anyway) is just as
          easy to get a long dash, and it doesn't throw wrenches into the cases when I
          need two ordinary dashes next to each other.


          Best regards,
          Tony.
          --
          "The Computer made me do it."

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • John R. Culleton
          ... I have a related problem that hasn t been answered yet. In a script I want to massage an html file by addressing its tags. First I want to put each tag on
          Message 4 of 9 , Aug 1 4:47 AM
          • 0 Attachment
            On Tuesday 31 July 2007, Tony Mechelynck wrote:
            > Kurt Smith wrote:
            > > On 7/31/07, Rainux <rainux@...> wrote:
            > >> I want when I typed "$this..var" in Vim, it can auto expand ".."
            > >> to "->" so I got "$this->var", I've tried the following command
            > >> in Vim, but it can work correctly.
            > >>
            > >> :iab .. ->
            > >
            > > With this abbreviation, VIM looks for a non-keyword character
            > > (usually a \s character, but other non-keyword chars work, too)
            > > after the ".." to trigger the abbreviation substitution. See :h
            > > 'iskeyword'. If you type a k.w. character after the .. it
            > > doesn't kick in, hence $this..var won't trigger, since the "v" is
            > > a keyword char.
            > >
            > > You could use
            > >
            > > :inoremap .. ->
            > >
            > > which will always work so long as you type the two dots within a
            > > 'timeout' period. See :help 'timeout'. If you'd like two dots
            > > next to each other, you'll need to type one dot, wait a 'timeout'
            > > period, and type the other.
            > >
            > > Maybe there is a better way; anyone else?
            > >
            > > HTH,
            > >
            > > Kurt
            >
            > No, I think you've hit it. There's always a balancing question
            > between "having the abbrev kick in when wanted" and "not kick in
            > when not wanted". .. as an {lhs} would, for instance, interfere
            > with a comment ending in three dots...
            >
            > I used to have
            >
            > :noreabbrev -- —
            >
            > in one script I used for HTML writing but I commented it out today:
            > it was kicking in too often, and interfering with <!-- comments -->
            >
            > I could work around it by using <dash><left><dash><right> but it
            > was a hassle. Writing out the entity (which I happen to have
            > memorized anyway) is just as easy to get a long dash, and it
            > doesn't throw wrenches into the cases when I need two ordinary
            > dashes next to each other.
            >
            >
            > Best regards,
            > Tony.

            I have a related problem that hasn't been answered yet. In a script I
            want to massage an html file by addressing its tags. First I want to
            put each tag on a line by itself. This means putting a \r before each
            < and a \r after each >. I tried the following commands for this
            editing but they seem not to work as written:
            :%s/\</\r\r\&/g
            :%s/\>/&\r\r/g

            Can anyone spot the flaws?

            --
            John Culleton



            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • John Beckett
            ... You ll get a lot of blank lines after the above. Following would condense ... John --~--~---------~--~----~------------~-------~--~----~ You received this
            Message 5 of 9 , Aug 1 5:22 AM
            • 0 Attachment
              John R. Culleton wrote:
              > This means putting a \r before each < and a \r after each >.

              In your example, you seem to want \r\r like this:
              :%s/</\r\r&/g
              :%s/>/&\r\r/g

              You'll get a lot of blank lines after the above. Following would condense
              them to a single blank line:

              :%s/\n\n\+/\r\r

              John


              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Tony Mechelynck
              John R. Culleton wrote: [...] ... As was already said in your earlier thread, the flaw is in using -- these mean start of word and end of word
              Message 6 of 9 , Aug 1 6:02 AM
              • 0 Attachment
                John R. Culleton wrote:
                [...]
                > I have a related problem that hasn't been answered yet. In a script I
                > want to massage an html file by addressing its tags. First I want to
                > put each tag on a line by itself. This means putting a \r before each
                > < and a \r after each >. I tried the following commands for this
                > editing but they seem not to work as written:
                > :%s/\</\r\r\&/g
                > :%s/\>/&\r\r/g
                >
                > Can anyone spot the flaws?
                >

                As was already said in your earlier thread, the flaw is in using \< and \> --
                these mean "start of word" and "end of word" respectively. To add a linebreak
                before every < and after every >, use (for instance)

                :%s/</\r</g
                :%s/>/>\r/g

                (without bacslashes before < and >) or, to apply it only to paired < and >

                :%s/<\_[^<>]*>/\r\0\r/g

                which translates as "whenever you see < followed by (any number of anything
                including linebreaks but not < or >) followed by >, add a linebreak before and
                after the whole match.

                The latter might break if there are unpaired < > in comments, but I think that
                even there they would break the HTML syntax.

                With doubled \r you'll get an empty line every time instead of just a linebreak.


                Best regards,
                Tony.
                --
                TALL KNIGHT: We are now no longer the Knights Who Say Ni!
                ONE KNIGHT: Ni!
                OTHERS: Sh!
                ONE KNIGHT: (wispers) Sorry.
                "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • John R. Culleton
                ... Thanks. The answer(s) to my earlier query didn t make it to me for some reason. -- John Culleton ATTN Publishers/authors: If you don t read you don t
                Message 7 of 9 , Aug 1 6:21 AM
                • 0 Attachment
                  On Wednesday 01 August 2007, Tony Mechelynck wrote:
                  > John R. Culleton wrote:
                  > [...]
                  >
                  > > I have a related problem that hasn't been answered yet. In a
                  > > script I want to massage an html file by addressing its tags.
                  > > First I want to put each tag on a line by itself. This means
                  > > putting a \r before each < and a \r after each >. I tried the
                  > > following commands for this
                  > >
                  > > editing but they seem not to work as written:
                  > > :%s/\</\r\r\&/g
                  > > :
                  > > :%s/\>/&\r\r/g
                  > >
                  > > Can anyone spot the flaws?
                  >
                  > As was already said in your earlier thread, the flaw is in using \<
                  > and \> -- these mean "start of word" and "end of word"
                  > respectively. To add a linebreak before every < and after every >,
                  > use (for instance)
                  >
                  > :%s/</\r</g
                  > :%s/>/>\r/g
                  >
                  > (without bacslashes before < and >) or, to apply it only to paired
                  > < and >
                  >
                  > :%s/<\_[^<>]*>/\r\0\r/g
                  >
                  > which translates as "whenever you see < followed by (any number of
                  > anything including linebreaks but not < or >) followed by >, add a
                  > linebreak before and after the whole match.
                  >
                  > The latter might break if there are unpaired < > in comments, but I
                  > think that even there they would break the HTML syntax.
                  >
                  > With doubled \r you'll get an empty line every time instead of just
                  > a linebreak.
                  >
                  >
                  > Best regards,
                  > Tony.

                  Thanks. The answer(s) to my earlier query didn't make it to me for
                  some reason.

                  --
                  John Culleton
                  ATTN Publishers/authors:
                  If you don't read you don't succeed.
                  Free short list of publishing/marketing books.
                  http://wexfordpress.com/tex/shortlist.pdf



                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Tony Mechelynck
                  John R. Culleton wrote: [...] ... Maybe wexfordexpress.com (or whatever) blocked those particular messages, thinking they were spam? Well, now you got it. Best
                  Message 8 of 9 , Aug 1 7:30 AM
                  • 0 Attachment
                    John R. Culleton wrote:
                    [...]
                    > Thanks. The answer(s) to my earlier query didn't make it to me for
                    > some reason.
                    >

                    Maybe wexfordexpress.com (or whatever) blocked those particular messages,
                    thinking they were spam? Well, now you got it.


                    Best regards,
                    Tony.
                    --
                    Government spending? I don't know what it's all about. I don't know
                    any more about this thing than an economist does, and, God knows, he
                    doesn't know much.
                    -- Will Rogers

                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • Rainux
                    Ah, I just forgot the insert mode mappings, this solved my question perfectly! Many thanks for your helps :) ... -- Best Regards Rainux
                    Message 9 of 9 , Aug 1 8:00 AM
                    • 0 Attachment
                      Ah, I just forgot the insert mode mappings, this solved my question perfectly!

                      Many thanks for your helps :)

                      On 8/1/07, Kurt Smith <kwmsmith@...> wrote:
                      >
                      > On 7/31/07, Rainux <rainux@...> wrote:
                      > >
                      > > I want when I typed "$this..var" in Vim, it can auto expand ".." to
                      > > "->" so I got "$this->var", I've tried the following command in Vim,
                      > > but it can work correctly.
                      > >
                      > > :iab .. ->
                      >
                      > With this abbreviation, VIM looks for a non-keyword character (usually
                      > a \s character, but other non-keyword chars work, too) after the ".."
                      > to trigger the abbreviation substitution. See :h 'iskeyword'. If you
                      > type a k.w. character after the .. it doesn't kick in, hence
                      > $this..var won't trigger, since the "v" is a keyword char.
                      >
                      > You could use
                      >
                      > :inoremap .. ->
                      >
                      > which will always work so long as you type the two dots within a
                      > 'timeout' period. See :help 'timeout'. If you'd like two dots next
                      > to each other, you'll need to type one dot, wait a 'timeout' period,
                      > and type the other.
                      >
                      > Maybe there is a better way; anyone else?
                      >
                      > HTH,
                      >
                      > Kurt
                      >
                      > >
                      >


                      --
                      Best Regards

                      Rainux

                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    Your message has been successfully submitted and would be delivered to recipients shortly.