Abbreviations add spaces when they shouldn't

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I'm trying to create an abbreviations to insert a comment and to insert a TODO comment. I wrote them as following:



iab co /*__*/<Left><Left><Left>


This one produces the following (where it has three spaces)



/*__|_*/


And for the TODO comment, I wrote it like this:



iab td /*_TODO:_*/<Left><Left><Left>


This one produces



/* TODO:____|_*/


For some reason, vim adds extra spaces when interpreting the abbreviations. Could someone tell me why does it do this and how can I solve it?



Note: I replaced spaces with underscores for clarity.










share|improve this question

























    up vote
    1
    down vote

    favorite












    I'm trying to create an abbreviations to insert a comment and to insert a TODO comment. I wrote them as following:



    iab co /*__*/<Left><Left><Left>


    This one produces the following (where it has three spaces)



    /*__|_*/


    And for the TODO comment, I wrote it like this:



    iab td /*_TODO:_*/<Left><Left><Left>


    This one produces



    /* TODO:____|_*/


    For some reason, vim adds extra spaces when interpreting the abbreviations. Could someone tell me why does it do this and how can I solve it?



    Note: I replaced spaces with underscores for clarity.










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I'm trying to create an abbreviations to insert a comment and to insert a TODO comment. I wrote them as following:



      iab co /*__*/<Left><Left><Left>


      This one produces the following (where it has three spaces)



      /*__|_*/


      And for the TODO comment, I wrote it like this:



      iab td /*_TODO:_*/<Left><Left><Left>


      This one produces



      /* TODO:____|_*/


      For some reason, vim adds extra spaces when interpreting the abbreviations. Could someone tell me why does it do this and how can I solve it?



      Note: I replaced spaces with underscores for clarity.










      share|improve this question













      I'm trying to create an abbreviations to insert a comment and to insert a TODO comment. I wrote them as following:



      iab co /*__*/<Left><Left><Left>


      This one produces the following (where it has three spaces)



      /*__|_*/


      And for the TODO comment, I wrote it like this:



      iab td /*_TODO:_*/<Left><Left><Left>


      This one produces



      /* TODO:____|_*/


      For some reason, vim adds extra spaces when interpreting the abbreviations. Could someone tell me why does it do this and how can I solve it?



      Note: I replaced spaces with underscores for clarity.







      abbreviations






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      Salahuddin Ahmed

      1545




      1545




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          This happens usually, because the abbreviation is triggered once you type a final space after the characters that trigger the abbreviation, e.g. after tdSpace, so that the final space gets added at the cursor position after your expanded abbreviation.



          One way around it is to make use of the Eatchar function mentioned at the help (there is no actual helptag for it, you can do :helpgrep Eatchar to find it).



          Here is the definition from the help together with your TODO abbreviation.



          func Eatchar(pat)
          let c = nr2char(getchar(0))
          return (c =~ a:pat) ? '' : c
          endfunc
          iab td /* TODO: */<Left><Left><Left><c-r>=Eatchar('s')<cr>





          share|improve this answer




















          • Super. You clarified it very well. For me it added more spaces because I was hitting tab after the trigger and not space. Now I modified the abbreviation so that the added space is considered in the abbreviation. Thank you
            – Salahuddin Ahmed
            2 hours ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "599"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f17692%2fabbreviations-add-spaces-when-they-shouldnt%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          This happens usually, because the abbreviation is triggered once you type a final space after the characters that trigger the abbreviation, e.g. after tdSpace, so that the final space gets added at the cursor position after your expanded abbreviation.



          One way around it is to make use of the Eatchar function mentioned at the help (there is no actual helptag for it, you can do :helpgrep Eatchar to find it).



          Here is the definition from the help together with your TODO abbreviation.



          func Eatchar(pat)
          let c = nr2char(getchar(0))
          return (c =~ a:pat) ? '' : c
          endfunc
          iab td /* TODO: */<Left><Left><Left><c-r>=Eatchar('s')<cr>





          share|improve this answer




















          • Super. You clarified it very well. For me it added more spaces because I was hitting tab after the trigger and not space. Now I modified the abbreviation so that the added space is considered in the abbreviation. Thank you
            – Salahuddin Ahmed
            2 hours ago














          up vote
          3
          down vote



          accepted










          This happens usually, because the abbreviation is triggered once you type a final space after the characters that trigger the abbreviation, e.g. after tdSpace, so that the final space gets added at the cursor position after your expanded abbreviation.



          One way around it is to make use of the Eatchar function mentioned at the help (there is no actual helptag for it, you can do :helpgrep Eatchar to find it).



          Here is the definition from the help together with your TODO abbreviation.



          func Eatchar(pat)
          let c = nr2char(getchar(0))
          return (c =~ a:pat) ? '' : c
          endfunc
          iab td /* TODO: */<Left><Left><Left><c-r>=Eatchar('s')<cr>





          share|improve this answer




















          • Super. You clarified it very well. For me it added more spaces because I was hitting tab after the trigger and not space. Now I modified the abbreviation so that the added space is considered in the abbreviation. Thank you
            – Salahuddin Ahmed
            2 hours ago












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          This happens usually, because the abbreviation is triggered once you type a final space after the characters that trigger the abbreviation, e.g. after tdSpace, so that the final space gets added at the cursor position after your expanded abbreviation.



          One way around it is to make use of the Eatchar function mentioned at the help (there is no actual helptag for it, you can do :helpgrep Eatchar to find it).



          Here is the definition from the help together with your TODO abbreviation.



          func Eatchar(pat)
          let c = nr2char(getchar(0))
          return (c =~ a:pat) ? '' : c
          endfunc
          iab td /* TODO: */<Left><Left><Left><c-r>=Eatchar('s')<cr>





          share|improve this answer












          This happens usually, because the abbreviation is triggered once you type a final space after the characters that trigger the abbreviation, e.g. after tdSpace, so that the final space gets added at the cursor position after your expanded abbreviation.



          One way around it is to make use of the Eatchar function mentioned at the help (there is no actual helptag for it, you can do :helpgrep Eatchar to find it).



          Here is the definition from the help together with your TODO abbreviation.



          func Eatchar(pat)
          let c = nr2char(getchar(0))
          return (c =~ a:pat) ? '' : c
          endfunc
          iab td /* TODO: */<Left><Left><Left><c-r>=Eatchar('s')<cr>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          Christian Brabandt

          14.5k2443




          14.5k2443











          • Super. You clarified it very well. For me it added more spaces because I was hitting tab after the trigger and not space. Now I modified the abbreviation so that the added space is considered in the abbreviation. Thank you
            – Salahuddin Ahmed
            2 hours ago
















          • Super. You clarified it very well. For me it added more spaces because I was hitting tab after the trigger and not space. Now I modified the abbreviation so that the added space is considered in the abbreviation. Thank you
            – Salahuddin Ahmed
            2 hours ago















          Super. You clarified it very well. For me it added more spaces because I was hitting tab after the trigger and not space. Now I modified the abbreviation so that the added space is considered in the abbreviation. Thank you
          – Salahuddin Ahmed
          2 hours ago




          Super. You clarified it very well. For me it added more spaces because I was hitting tab after the trigger and not space. Now I modified the abbreviation so that the added space is considered in the abbreviation. Thank you
          – Salahuddin Ahmed
          2 hours ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f17692%2fabbreviations-add-spaces-when-they-shouldnt%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          Confectionery