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

regular expressions in abbreviations

Expand Messages
  • Aaron Webster
    Hi all, I m looking for a way to use regular expressions in abbreviations. For example, ... would would expand every instance of, 50nm to
    Message 1 of 4 , Jan 21, 2013
    • 0 Attachment
      Hi all, I'm looking for a way to use regular expressions in abbreviations. For example,

      :iab \([0-9]\{-}\)nm \\SI{\1}{\\nano\\meter}

      would would expand every instance of, '50nm' to '\SI{50}{\nano\meter}'. Is this possible? It's been suggested to imap a regular function, but this is not so satisfying.

      --
      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
    • Ben Fritz
      ... It *might* be possible to change the preceding text as you desire using an based abbreviation on nm . It would be easier with a mapping. What you
      Message 2 of 4 , Jan 21, 2013
      • 0 Attachment
        On Monday, January 21, 2013 3:56:48 AM UTC-6, Aaron Webster wrote:
        > Hi all, I'm looking for a way to use regular expressions in abbreviations. For example,
        >
        > :iab \([0-9]\{-}\)nm \\SI{\1}{\\nano\\meter}
        >
        > would would expand every instance of, '50nm' to '\SI{50}{\nano\meter}'. Is this possible? It's been suggested to imap a regular function, but this is not so satisfying.

        It *might* be possible to change the preceding text as you desire using an <expr> based abbreviation on "nm". It would be easier with a mapping. What you cannot do is specify abbreviations or mappings using regular expressions as you are trying to do above.

        --
        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
      • Tim Chase
        ... While a bit ugly, you can do it with the following: function! ExpandSI() let l:cword = expand( ) if l:cword=~ ^ d +n$ let l:num = l:cword[:-2]
        Message 3 of 4 , Jan 21, 2013
        • 0 Attachment
          On 01/21/13 03:56, Aaron Webster wrote:
          > Hi all, I'm looking for a way to use regular expressions in abbreviations. For example,
          >
          > :iab \([0-9]\{-}\)nm \\SI{\1}{\\nano\\meter}
          >
          > would would expand every instance of, '50nm' to '\SI{50}{\nano\meter}'. Is this possible? It's been suggested to imap a regular function, but this is not so satisfying.

          While a bit ugly, you can do it with the following:

          function! ExpandSI()
          let l:cword = expand('<cword>')
          if l:cword=~'^\d\+n$'
          let l:num = l:cword[:-2]
          return "\<c-w>\\SI{".(l:num)."}{\\nano\\meter}"
          endif
          return 'm'
          endfunction
          :inoremap <expr> m ExpandSI()

          which will trigger on each letter "m", expanding if it matches
          "\d\+n" before it. This works for non-negative integers. More work
          would need to be done to handle negative numbers or decimal numbers.

          -tim





          --
          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
        • Christian Brabandt
          Hi Tim! ... You probably waht this to be buffer-local (and be loaded by a filetype plugin). Mit freundlichen Grüßen Christian -- Die Dummheit drängt sich
          Message 4 of 4 , Jan 21, 2013
          • 0 Attachment
            Hi Tim!

            On Mo, 21 Jan 2013, Tim Chase wrote:

            > On 01/21/13 03:56, Aaron Webster wrote:
            > >Hi all, I'm looking for a way to use regular expressions in abbreviations. For example,
            > >
            > > :iab \([0-9]\{-}\)nm \\SI{\1}{\\nano\\meter}
            > >
            > >would would expand every instance of, '50nm' to '\SI{50}{\nano\meter}'. Is this possible? It's been suggested to imap a regular function, but this is not so satisfying.
            >
            > While a bit ugly, you can do it with the following:
            >
            > function! ExpandSI()
            > let l:cword = expand('<cword>')
            > if l:cword=~'^\d\+n$'
            > let l:num = l:cword[:-2]
            > return "\<c-w>\\SI{".(l:num)."}{\\nano\\meter}"
            > endif
            > return 'm'
            > endfunction
            > :inoremap <expr> m ExpandSI()
            >
            > which will trigger on each letter "m", expanding if it matches
            > "\d\+n" before it. This works for non-negative integers. More work
            > would need to be done to handle negative numbers or decimal numbers.

            You probably waht this to be buffer-local (and be loaded by a filetype
            plugin).

            Mit freundlichen Grüßen
            Christian
            --
            Die Dummheit drängt sich vor, um gesehen zu werden; die Klugheit steht
            zurück, um zu sehen.
            -- Sylva Carmen (pseud. Elisabeth, Königin von Rumänien)

            --
            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
          Your message has been successfully submitted and would be delivered to recipients shortly.