Regex vim缩写和正则表达式

Regex vim缩写和正则表达式,regex,vim,abbreviation,Regex,Vim,Abbreviation,在vim中,是否可以在缩写中使用正则表达式?比如说 :iab \([0-9]\{-}\)nm \\SI{\1}{\\nano\\meter} imap <silent> <leader>obscure-key-of-choice <Esc>:%s/\v(\d+)nm/\\SI{\1}{\\nano\\meter}/g<CR>``i 50nm blabla 73nm your-interesting-science-here 89nm ... s

在vim中,是否可以在缩写中使用正则表达式?比如说

:iab \([0-9]\{-}\)nm \\SI{\1}{\\nano\\meter}
imap <silent> <leader>obscure-key-of-choice <Esc>:%s/\v(\d+)nm/\\SI{\1}{\\nano\\meter}/g<CR>``i
50nm blabla 73nm your-interesting-science-here 89nm
... some new lines...
we love nanometers nm! 34nm and finally 18nm
\SI{50}{\nano\meter} blabla \SI{73}{\nano\meter} your-interesting-science-here \SI{89}{\nano\meter}
... some new lines...
we love nanometers nm! \SI{34}{\nano\meter} and finally \SI{18}{\nano\meter}

会将的每个实例,比如说,“50nm”扩展到“\SI{50}{\nano\meter}”。

最好的办法是为自己编写一个小助手函数。点击全向补全或用户定义的补全(
C-x C-u
,请参见
:help'cfu'
)是一个不错的选择。我在一个键上绘制了一个常规函数来imap:

function! ExpandNanometers()
    let items = matchlist(expand('<cword>'), '\v(\d+)nm')
    if len(items) == 0
        return 
    endif
    let modified = '\SI{' . items[1] . '}{\nano\meter}'
    exec "normal! ciw" . modified
endf
imap <C-l> <C-o>:call ExpandNanometers()<CR>
函数!可膨胀纳米()
让items=matchlist(展开(“”),“\v(\d+)nm”)
如果长度(项目)==0
返回
恩迪夫
让modified='\SI{.items[1].}{\nano\meter}'
执行“正常!ciw”。被改进的
endf
imap:调用ExpandNanometers()

也许不是最好的代码。在插入模式下绑定
C-l
,如果光标在单词上或紧跟在单词后面,它会将
50nm
之类的单词替换为所需的单词。

我想在前面的答案中添加这一点作为注释,但显然我要到50代表才能完成。我也知道这已经太迟了,但出于参考目的:

如果键映射是可接受的(按照前面的答案),那么

:iab \([0-9]\{-}\)nm \\SI{\1}{\\nano\\meter}
imap <silent> <leader>obscure-key-of-choice <Esc>:%s/\v(\d+)nm/\\SI{\1}{\\nano\\meter}/g<CR>``i
50nm blabla 73nm your-interesting-science-here 89nm
... some new lines...
we love nanometers nm! 34nm and finally 18nm
\SI{50}{\nano\meter} blabla \SI{73}{\nano\meter} your-interesting-science-here \SI{89}{\nano\meter}
... some new lines...
we love nanometers nm! \SI{34}{\nano\meter} and finally \SI{18}{\nano\meter}
有点像

:iab \([0-9]\{-}\)nm \\SI{\1}{\\nano\\meter}
imap <silent> <leader>obscure-key-of-choice <Esc>:%s/\v(\d+)nm/\\SI{\1}{\\nano\\meter}/g<CR>``i
50nm blabla 73nm your-interesting-science-here 89nm
... some new lines...
we love nanometers nm! 34nm and finally 18nm
\SI{50}{\nano\meter} blabla \SI{73}{\nano\meter} your-interesting-science-here \SI{89}{\nano\meter}
... some new lines...
we love nanometers nm! \SI{34}{\nano\meter} and finally \SI{18}{\nano\meter}

你试过了吗?行了吗?行一行怎么样?
:iab.*今天的工作完成了。
Har。但vim只是逐字解释“.*”和我上面的表达式。