1

I currently have the following line in my vimrc to highlight lines longer than 80 characters wide.

match ErrorMsg '\%>80v.\+

I would like this rule to be disabled when I am editing a SQL file, so I tried adding this line based on what I read in the help.

 autocmd BufNew,BufRead *.sql :match ErrorMsg none

However, this throws the following error whenever I load a sql file.

Error detected while processing BufRead Auto commands for "*.sql":
E488: Trailing characters: :match ErrorMsg none
Press ENTER or type command to continue

How can I make it work without throwing the error?

merlin2011
  • 71,677
  • 44
  • 195
  • 329

2 Answers2

2

Get rid of the highlight group. (colon removed since it doesn't affect the outcome)

autocmd BufNew,BufRead *.sql match none

You are only allowed 3 matches and you need to use either match, 2match or 3match. So you only need to clear the specific one that you used

Notice how in :h :match {group} is not listed in the syntax for match none

:mat[ch]
:mat[ch] none
                Clear a previously defined match pattern.
FDinoff
  • 30,689
  • 5
  • 75
  • 96
0

Note: In recent Vim 7.3+ versions, you can alternatively use:

:setlocal colorcolumn=81

in your otherwise identical :autocmd.

Also note that both this and your :match are window-local, so if you switch buffers, the highlighting will persist. To completely fix this (mere nuisance) would require more elaborate autocmds.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324