Monday, January 21, 2013

Re: regular expressions in abbreviations

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

No comments: