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
Monday, January 21, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment