高亮显示光标下的单词,光标下的单词除外


1

我有一个 autocmd 由...引发 CursorMoved 那将 match 与光标下的单词相同的单词作为简单地反转前景/背景的语法规则。

我用它来查找等于光标下的所有单词以进行即时拼写检查。这里是:

autocmd CursorMoved * exe printf('match lCursor /\V\<%s\>/', escape(expand('<cword>'), '/\'))

如何从匹配中排除当前行?

Answers:


1

要避免当前行上的任何匹配,您可以使用 :help /\%l 特殊原子匹配当前行号,然后断言不匹配通过 消极的向前看

exe printf('match lCursor /\V\%%%dl\@!\<%s\>/', line('.'), escape(expand('<cword>'), '/\'))

但在你的回答中你也表明了 现在的话 (不是整行)不应突出显示。这可以通过负前瞻再次实现,断言光标( \%# )不在当前关键字内( \<\k*...\k*\>\& )也匹配当前的单词:

exe printf('match lCursor /\V\%%(\<\k\*\%%#\k\*\>\)\@!\&\<%s\>/', escape(expand('<cword>'), '/\'))
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.