Last active
March 21, 2024 00:55
-
-
Save atomicstack/e431d5ea674adc7c65374d83c9478782 to your computer and use it in GitHub Desktop.
a custom ~/.config/nvim/syntax/tmux.vim file which fixes colour definitions
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
" inspired by https://stackoverflow.com/a/69141482 | |
" the existing highlight rules for tmux.vim create a bunch of highlight definitions similar to this: | |
" for i in range(0,255) | |
" hi tmuxColour$i ctermfg=$i | |
" ...but in neovim, this just resulted in plain white text. after looking at the output of :highlight | |
" in vim for a while, it seemed that other entries with guifg definitions were showing the right colour, | |
" and indeed, the fix was to instead specify RGB values for the guifg style. | |
if get(g:, "tmux_syntax_colors", 1) | |
function! GetRGBColor(index) | |
let rgb = '' | |
if a:index < 16 | |
" Standard 16 colors (naive conversion), looks bad | |
" let std_colors = ['#000000', '#800000', '#008000', '#808000', '#000080', '#800080', '#008080', '#C0C0C0', '#808080', '#FF0000', '#00FF00', '#FFFF00', '#0000FF', '#FF00FF', '#00FFFF', '#FFFFFF'] | |
" Standard 16 colors, but lifted from Kitty.app on MacOS | |
let std_colors = [ '#000000', '#BB281B', '#5FC83B', '#9D9B31', '#3471C6', '#BA32CA', '#5ECACB', '#C0C0C0', '#808080', '#DE3B2F', '#00FF00', '#FFFF00', '#448DF7', '#FF00FF', '#00FFFF', '#FFFFFF' ] | |
let rgb = std_colors[a:index] | |
elseif a:index < 232 | |
" 6x6x6 color cube | |
let r = (((a:index - 16) / 36) % 6) | |
let g = (((a:index - 16) / 6) % 6) | |
let b = ((a:index - 16) % 6) | |
let rgb = printf('#%02x%02x%02x', r ? (55 + r * 40) : 0, g ? (55 + g * 40) : 0, b ? (55 + b * 40) : 0) | |
else | |
" Grayscale | |
let gray = 8 + (a:index - 232) * 10 | |
let rgb = printf('#%02x%02x%02x', gray, gray, gray) | |
endif | |
return rgb | |
endfunction | |
for s:i in range(0, 255) | |
let s:bg = (!s:i || s:i == 16 || (s:i > 231 && s:i < 235)) ? 'guibg=#FFFFFF' : '' | |
let s:fg = GetRGBColor(s:i) | |
exec "syn match tmuxColour" . s:i . " /\\<colou\\?r" . s:i . "\\>/ display" | |
\ . " | highlight tmuxColour" . s:i . " guifg=" . s:fg . " " . s:bg | |
endfor | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment