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

Trailing space with UltiSnips snippet

Expand Messages
  • Marco
    Hi, I use the UltiSnips¹ plugin and have a snippet as follows: snippet sst start${1} ${2} ${3} stop${1/ s*//g} $0 endsnippet This works fine if I provide an
    Message 1 of 3 , Sep 8 4:33 AM
    • 0 Attachment
      Hi,

      I use the UltiSnips¹ plugin and have a snippet as follows:

      snippet sst
      \start${1} ${2}
      ${3}
      \stop${1/\s*//g}
      $0
      endsnippet

      This works fine if I provide an argument for the start command:

      sst<trigger>foo<trigger>bar<trigger> leads to

      \startfoo bar

      \stopfoo

      But this snippet should also work without an argument, but it leaves
      a trailing space:

      sst<trigger>foo<trigger><trigger> leads to

      \startfoo

      \stopfoo

      How do I define this snippet so it doesn't leave the trailing space
      when no argument is provided?

      Marco

      ¹ https://github.com/SirVer/ultisnips

      --
      --
      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.
    • Michael Henry
      ... [...] ... I think the s flag may be what you re looking for. From the UltiSnips help: s Remove whitespace immediately before the cursor at the end of
      Message 2 of 3 , Sep 8 2:13 PM
      • 0 Attachment
        On 09/08/2013 07:33 AM, Marco wrote:
        > I use the UltiSnipsน plugin and have a snippet as follows:
        >
        > snippet sst
        > \start${1} ${2}
        > ${3}
        > \stop${1/\s*//g}
        > $0
        > endsnippet
        [...]
        > But this snippet should also work without an argument, but it leaves
        > a trailing space:

        I think the "s" flag may be what you're looking for. From the
        UltiSnips help:

        s Remove whitespace immediately before the cursor at the end of a line
        before jumping to the next tabstop. This is useful if there is a
        tabstop with optional text at the end of a line.

        Using that flag, your definition becomes:

        snippet sst "some description" s
        \start${1} ${2}
        ${3}
        \stop${1/\s*//g}
        $0
        endsnippet

        See the following section in the help for more information:

        :help UltiSnips-syntax

        Michael Henry

        --
        --
        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.
      • Marco
        ... That was exactly what I was looking for. I apparently missed that while reading the manual. Thanks a lot. Marco
        Message 3 of 3 , Sep 8 3:45 PM
        • 0 Attachment
          On 2013–09–08 Michael Henry wrote:

          > > But this snippet should also work without an argument, but it leaves
          > > a trailing space:
          >
          > I think the "s" flag may be what you're looking for. From the
          > UltiSnips help:
          >
          > s Remove whitespace immediately before the cursor at the end of a line
          > before jumping to the next tabstop. This is useful if there is a
          > tabstop with optional text at the end of a line.

          That was exactly what I was looking for. I apparently missed that
          while reading the manual. Thanks a lot.

          Marco
        Your message has been successfully submitted and would be delivered to recipients shortly.