Created
March 30, 2010 00:14
-
-
Save frogonwheels/348591 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Name: IndentHL2.vim | |
" | |
" Vim Syntax Highlighting for indent whitespace | |
" | |
" Last change: 2010 Mar 30 | |
" Version: 0.4 | |
" Modified By: Michael Geddes<vimmer at frog dot wheelycreek dot net> | |
" Original Author: Vedran Sajko <vsajko at oglasnik dot hr> | |
" Install: | |
" Put script in ~/.vim/plugins/ | |
" And call IndentHLToggle to enable it. | |
" | |
" Tabs and spaces are colored in slightly different colors from lightest to | |
" darkest for dark background or from darkest to lightest for light background | |
" example (x is darkest color and z lightest): | |
" | |
" function foo() | |
" x if b | |
" x y echo 'something' | |
" x y while c | |
" x y z echo 'something else' | |
" x y endwhile | |
" x endif | |
" endfunction | |
" Actually script forms vertical stripes | |
" | |
" Usage: | |
" You can switch it off and on by | |
" | |
" :IndentHLToggle | |
" | |
" | |
" History: | |
" 0.3 - Use MatchAdd (move away from syntax dependance) | |
" 0.2 - support for light background, | |
" corrected some bugs | |
" and some checking added | |
" 0.1 - initial version | |
" | |
" | |
" Colors can be changed by changing these values | |
" This is values whitch is added to color | |
" (basic darkest color for dark background is 'Normal bg') | |
let s:tabRadd = 0x00 "(red for tab) | |
let s:tabGadd = 0x00 "(green for tab) | |
let s:tabBadd = 0x11 "(blue for tab) | |
let s:spRadd = 0x00 "(red for space) | |
let s:spGadd = 0x11 "(green for space) | |
let s:spBadd = 0x00 "(blue for space) | |
function! s:ChekingAdd(val) | |
if a:val < 0 && &background == 'dark' | |
let retv = -a:val | |
elseif a:val > 0 && &background == 'light' | |
let retv = -a:val | |
else | |
let retv = a:val | |
endif | |
if retv > 0 && retv > 0xDD | |
return 0xDD | |
endif | |
if retv < 0 && retv < -0xdd | |
return -0xdd | |
endif | |
return retv | |
endfunction | |
"Convert decimal to hexadecimal with help of Dec2hex16 | |
function! s:Dec2hexcol(val) | |
return printf('%.2x',a:val) | |
endfunction | |
"Defines a syntax for indent-spaces and indent-tabs separately | |
function! s:SynMatchTS() | |
let w:IndentHL_matches=[] | |
let n = 0 | |
while n <= 12 | |
let startc = &sw * n | |
let endc=startc+&sw+1 | |
call add(w:IndentHL_matches,matchadd( 'Tab'.n , '\%>'.startc.'v\%<'.endc.'v\(^\s*\)\@<=\t')) | |
call add(w:IndentHL_matches,matchadd( 'Space'.n , '\%>'.startc.'v\%<'.endc.'v\(^\s*\)\@<= ')) | |
let n += 1 | |
endwhile | |
return 1 | |
endfunction | |
"Defines Highlighting Colors | |
function! s:HiDefST() | |
let m = 0 | |
let sp = 0 | |
while m <= 3 | |
let n=0 | |
" gets current normal background color for starting point | |
let boja = synIDattr(synIDtrans(hlID("Normal")), "bg#", 'GUI') | |
if strlen (boja) < 7 && &background == 'light' | |
let boja = '#ffffff' | |
elseif strlen (boja) < 7 && &background == 'dark' | |
let boja = '#000000' | |
endif | |
let tabRaddc = s:ChekingAdd(s:tabRadd) | |
let tabGaddc = s:ChekingAdd(s:tabGadd) | |
let tabBaddc = s:ChekingAdd(s:tabBadd) | |
let spRaddc = s:ChekingAdd(s:spRadd) | |
let spGaddc = s:ChekingAdd(s:spGadd) | |
let spBaddc = s:ChekingAdd(s:spBadd) | |
let bojaR='0x' . boja[1] . boja[2] | |
let bojaG='0x' . boja[3] . boja[4] | |
let bojaB='0x' . boja[5] . boja[6] | |
if &background == 'dark' | |
let bojaR = bojaR + 0x22 | |
let bojaG = bojaG + 0x22 | |
let bojaB = bojaB + 0x22 | |
else | |
let bojaR = bojaR - 0x22 | |
let bojaG = bojaG - 0x22 | |
let bojaB = bojaB - 0x22 | |
endif | |
while n <= 2 | |
exe 'hi def Tab'. sp .' guibg=#'. s:Dec2hexcol(bojaR+tabRaddc) . s:Dec2hexcol(bojaG+tabGaddc) . s:Dec2hexcol(bojaB+tabBaddc) | |
exe 'hi def Space'. sp .' guibg=#'. s:Dec2hexcol(bojaR+spRaddc) . s:Dec2hexcol(bojaG+spGaddc) . s:Dec2hexcol(bojaB+spBaddc) | |
if &background == 'dark' | |
let bojaR = bojaR - 0x11 | |
let bojaG = bojaG - 0x11 | |
let bojaB = bojaB - 0x11 | |
endif | |
if &background == 'light' | |
let bojaR = bojaR + 0x11 | |
let bojaG = bojaG + 0x11 | |
let bojaB = bojaB + 0x11 | |
endif | |
let n += 1 | |
let sp += 1 | |
endwhile | |
let m += 1 | |
endwhile | |
endfunction | |
"for switching indent highlighting off and on | |
function! s:OnOffIndentHi() | |
if ! exists('w:IndentHL_matches') | |
call s:HiDefST() | |
call s:SynMatchTS() | |
else | |
for x in w:IndentHL_matches | |
call matchdelete(x) | |
endfor | |
unlet w:IndentHL_matches | |
endif | |
endfunction | |
com! -nargs=0 IndentHLToggle call s:OnOffIndentHi() | |
IndentHLToggle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment