Skip to content

Instantly share code, notes, and snippets.

@MrOrz
Created August 12, 2011 11:26
Show Gist options
  • Save MrOrz/1141879 to your computer and use it in GitHub Desktop.
Save MrOrz/1141879 to your computer and use it in GitHub Desktop.
hexHighlight.vim supporting #AAA syntax
"gvim plugin for highlighting hex codes to help with tweaking colors
"Last Change: 2010 Jan 21
"Maintainer: Yuri Feldman <feldman.yuri1@gmail.com>
"License: WTFPL - Do What The Fuck You Want To Public License.
"Email me if you'd like.
let s:HexColored = 0
let s:HexColors = []
map <Leader><F2> :call HexHighlight()<Return>
function! HexHighlight()
if has("gui_running")
if s:HexColored == 0
let hexGroup = 4
let lineNumber = 0
while lineNumber <= line("$")
let currentLine = getline(lineNumber)
let hexLineMatch = 1
while match(currentLine, '\(#\x\{6}\)\|\(#\x\{3}\)', 0, hexLineMatch) != -1
let hexMatch = matchstr(currentLine, '\(#\x\{6}\)\|\(#\x\{3}\)', 0, hexLineMatch)
exe 'hi hexColor'.hexGroup.' guifg='.hexMatch.' guibg='.hexMatch
exe 'let m = matchadd("hexColor'.hexGroup.'", "'.hexMatch.'", 25, '.hexGroup.')'
let s:HexColors += ['hexColor'.hexGroup]
let hexGroup += 1
let hexLineMatch += 1
endwhile
let lineNumber += 1
endwhile
unlet lineNumber hexGroup
let s:HexColored = 1
echo "Highlighting hex colors..."
elseif s:HexColored == 1
for hexColor in s:HexColors
exe 'highlight clear '.hexColor
endfor
call clearmatches()
let s:HexColored = 0
echo "Unhighlighting hex colors..."
endif
else
echo "hexHighlight only works with a graphical version of vim"
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment