Vim syntax coloring: How do I highlight long lines only?

廉价感情. 提交于 2019-11-28 06:54:05
Ciro Santilli 新疆改造中心996ICU六四事件

I needed the autocomand to work for me:

augroup vimrc_autocmds
  autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#111111
  autocmd BufEnter * match OverLength /\%75v.*/
augroup END

Also like the idea of using 75 if you are aiming at 80 columns in average.

Taken from:

http://blog.ezyang.com/2010/03/vim-textwidth/

Possible reason why it fails without BufEnter: highlight + match can only be used once. Multiple usage means that old ones are overridden. How to add multiple highlights

HS.

I have this in my vimrc.
I found it here: Vim 80 column layout concerns

highlight OverLength ctermbg=darkred ctermfg=white guibg=#FFD9D9
match OverLength /\%81v.*/

You might want to adjust the colors to your preferences.

Since I do not like the Vim 7.3 column marker, I just use the highlight text after column 80... at least that is what I want 95% of the time.

For the other 5% of the time, I wrote this small extension to also have a quick way to disable the highlight:

https://gist.github.com/fgarcia/9704429#file-long_lines-vim

I use the following method:

hi gitError ctermbg=Red
match gitError /^.*\s$/
2match gitError /^.\{120\}.*$/

(These match some git pre-commit hooks)

The second line should be of interrest to you.

This uses an autocommand to adjust the OverLength value to match your file type.

" highlight lines longer than `textwidth` size for each filetype
autocmd FileType *
    \ if &textwidth |
    \    exec 'match OverLength /\%' . string(&textwidth+2) . 'v.*/' |
    \ endif
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!