简略版:我想在.vimrc上做这样的事情
let my_regex = "some regex"
autocmd Syntax * syn match CamelCase my_regex transparent containedin=.*Comment.*,.*String.*,VimwikiLink contains=@NoSpell contained但它显然不起作用-变量my_regex没有展开或识别。如果我直接用它的内容替换变量--它工作得很好。我在这里错过了什么?
故事:在搜索了一下之后,我发现了一个技巧这里,它使vim的拼写检查忽略骆驼大小写单词(上下)。但是我把regex扩展到忽略了其他几个词,这个表达变得非常丑陋。所以,我试着做这样的事情:
" ignore camel case "
let vim_spellcheck_ignore_words = "\(\<\|_\)\%(\u\l*\)\{2,}\(\>\|_\)\|\<\%(\l\l*\)\%(\u\l*\)\{1,}\>"
" ignore upper-case only words "
let vim_spellcheck_ignore_words = vim_spellcheck_ignore_words . "\|\<[A-Z]*\>"
" ignore words, which contain '_' or a digit "
let vim_spellcheck_ignore_words = vim_spellcheck_ignore_words . "\|\<[a-zA-Z_]*[0-9_]\+[0-9a-zA-Z_]*\>"
" something ese .. "
let vim_spellcheck_ignore_words = vim_spellcheck_ignore_words . "something"
autocmd Syntax * syn match CamelCase vim_spellcheck_ignore_words transparent containedin=.*Comment.*,.*String.*,VimwikiLink contains=@NoSpell contained最后解决办法:
" begin regex "
let vim_spellcheck_ignore_words = "/"
" ignore upper and lower camel case words "
let vim_spellcheck_ignore_words = vim_spellcheck_ignore_words . "\\(\\<\\|_\\)\\%(\\u\\l*\\)\\{2,}\\(\\>\\|_\\)\\|\\<\\%(\\l\\l*\\)\\%(\\u\\l*\\)\\{1,}\\>"
" ignore all-caps words "
let vim_spellcheck_ignore_words = vim_spellcheck_ignore_words . "\\|\\<[A-Z]*\\>"
" ignore words, which contain a digit or '_' "
let vim_spellcheck_ignore_words = vim_spellcheck_ignore_words . "\\|\\<[a-zA-Z_]*[0-9_]\\+[0-9a-zA-Z_]*\\>"
" end of regex "
let vim_spellcheck_ignore_words = vim_spellcheck_ignore_words . "/"
autocmd Syntax * exe "syn match CamelCase" vim_spellcheck_ignore_words "transparent containedin=.*Comment.*,.*String.*,VimwikiLink contains=@NoSpell contained"解决办法摘要(基于初步办法):
//中包围正则表达式exe (execute)计算表达式备选方案:
autocmd Syntax * syn match CamelCase
\ "\(\<\|_\)\%(\u\l*\)\{2,}\(\>\|_\)\|\<\%(\l\l*\)\%(\u\l*\)\{1,}\>
\ \|\<[A-Z]*\>
\ \|\<[a-zA-Z_]*[0-9_]\+[0-9a-zA-Z_]*\>"
\ transparent containedin=.*Comment.*,.*String.*,VimwikiLink contains=@NoSpell contained发布于 2016-01-05 15:42:06
syn不需要一个表达式。我不记得确切地知道ex命令期望从:exe、:let和:echo系列命令中获得一个表达式。因此,如果要使用变量,必须使用:exe命令来插入变量:
autocmd Syntax * exe "syn match CamelCase" my_regex "transparent containedin=.*Comment.*,.*String.*,VimwikiLink contains=@NoSpell contained"发布于 2016-01-05 15:43:55
我希望我能正确理解你的问题。
要动态地“构建”命令/自动you,可以使用:execute如下:
autocmd Syntax * exe "syn match CamelCase " . variable ." .... rest commands"https://stackoverflow.com/questions/34614982
复制相似问题