jacquard
jacquard

Reputation: 1307

Dynamic pattern for vim highlight

In the vim help, there is a suggestion to use highlight groups for highlighting text greater than the textwidth:

Another example, which highlights all characters in virtual column 72 and more: :highlight rightMargin term=bold ctermfg=blue guifg=blue :match rightMargin /.\%>72v/

I would like this to always reflect the value of texwidth setup. Something like:

match rightMargin /%\=&textwidthv.*/

But this doesn't give me what is expected. Can you help me to parameterize OverLength with the actual value of textwitdh.

NB: I plan to put this in a filetype autocommand block , inside which, there would be a set to textwidth option and redefinition of the rightMargin highlight group.

I realize that this parameterization will not save me any lines of code, but I just want to know if this is possible at all in vim.

Upvotes: 2

Views: 138

Answers (1)

lcd047
lcd047

Reputation: 5861

One way to do it:

call matchadd('rightMargin', '\%'. &tw .'v')

You should probably put this in a ftplugin (see :help ftplugin) rather than an autocmd.

Upvotes: 1

Related Questions