开发者

GVim: Different colors of odd and even lines

开发者 https://www.devze.com 2023-02-15 04:18 出处:网络
Can I create color scheme f开发者_运维问答or GVim (MacVim) where odd lines and even lines will have different colors?A Google search turned this up (I didn\'t know how to do it, but your question made

Can I create color scheme f开发者_运维问答or GVim (MacVim) where odd lines and even lines will have different colors?


A Google search turned this up (I didn't know how to do it, but your question made me curious). Post below.


Got it to work on text files, as follows (on W32)

---- ~/vimfiles/after/syntax/text.vim 
hi default Oddlines ctermbg=grey guibg=#808080 
hi default Evenlines cterm=NONE gui=NONE 

syn match Oddlines "^.*$" contains=ALL nextgroup=Evenlines skipnl 
syn match Evenlines "^.*$" contains=ALL nextgroup=Oddlines skipnl 

---- $VIM/vimfiles/after/filetype.vim 
augroup filetypedetect 
        au BufRead,BufNewFile *.txt setf text 
augroup END 

---- ~/vimfiles/colors/almost-default.vim 
[...] 
hi Oddlines ctermbg=yellow guibg=#FFFF99 
hi Evenlines ctermbg=magenta guibg=#FFCCFF 
[...] 

Notes: 1. filetype.vim in an "after-directory" and with ":setf" to avoid overriding already-detected "special" .txt files.

  1. With "default" before the highlight name in the syntax file (but not without it) the colors from the colorscheme (invoked from the vimrc) are used. (Without a colorscheme, the "default" colors from the syntax file are still used.)

  2. Haven't succeeded (but haven't much tried) to make it work for a more complex filetype with an already defined syntax like HTML

  3. After entering the above changes, Vim must be restarted for them to take effect.

OK, enough for now, I'm taking a nap. Best regards, Tony.

0

精彩评论

暂无评论...
验证码 换一张
取 消