256è²ãªvimã¨æ¯ããããã®.vimrc
æè¿è¨³ãã£ã¦Terminal.appã«ãããã°ãã¦ãiTermã«ããã«ã¡ã¯ãã¾ããã
Terminal.appã¯ãããç´ æµã§å¥½ããªãã ãã©xterm-256colorã«ãªã£ã¦ãããªãã®ããããæ®å¿µã
ãã¨jabannerã ã¨ãã¿ã¼ããã«ã§ãã¬ã¼ã³ã ã¨ããã£ã¡ããèªåã«ã¯256è²ã®ã¿ã¼ããã«ã¯ãããé
åçã§...ã
ã¹ã¯ãã¼ã«ããã¨æåãå£ããããã¦ã£ã³ãã¦ãå·¡åã®ãã£ãã©ã«ãã®ã·ã§ã¼ãã«ããããããæ¼ãã¥ããã£ããããªãã ãã©iTerm使ç¨ä¸now!
ã§ãæè§256è²åºãã¿ã¼ããã«ãªã®ã§vimã256è²åãããæã
è²ã
調ã¹ã¦ãã°ã°ã£ã¦ãä¸å¿è¦ãæ¸ãç¨åº¦ã®ã¾ã¨ãã
ã¾ããvimã256è²ã«å¯¾å¿ãããã
é¢é£help㯠:help xterm-color ãããã
t_Coã ã¨ãt_AF, t_ABã¨ãããªãã·ã§ã³ããããã®ãä¸ã¤ã®æããããããããããã¹ãã¼ããªã®ã¯TERMç°å¢å¤æ°ããããæ¹æ³ã
iTermãªãBookmarks -> Manage Profiles... ãéãã¦ãTerminal Profilesããç¾å¨ä½¿ã£ã¦ããç©ãé¸æãªããdupãã¦Typeãxterm-256colorã«å¤æ´ï¼
ã¦ã£ã³ãã¦ãéãç´ãã¦ãecho $TERMã§xterm-256colorãåºãã°ok
vimãèµ·åãã¦ãé©å½ãªã¹ã¿ã¤ã«ãããã£ã¦ã¿ã¦256è²ã«ãªã£ã¦ããããã§ã(å¤
æã£åãæ©ã確ãããã«ã¯ã :set number ãã¦ã :highlight LineNr ctermfg=196 ã§è¡çªå·ãçã£èµ¤ã«ãªãã°ok
ãã¨ãã赤ã ã£ãããåãããªããï¼ã¨ããå¥ç¹ãªè²ç°å¢ã®æ¹ã¯ :highlight LineNr ctermfg=21 ã§çã£éã«ãªãã°ok
è²çªå·ã255ã¾ã§ä½¿ããããã«ãªãã15ã¾ã§ãåºæ¬è²ã231ã¾ã§ãã«ã©ã¼ãã¥ã¼ãè²ããã以éãã°ã¬ã¼ã¹ã±ã¼ã«ã¨ãªã£ã¦ããããã§ãã
id:kakurasan:20080703 ã«è©³ããæ¸ããã¦ããã®ã§ããã¡ãã®æ¹ãè¦ãæ¹ãæ©ãã¨æãã¾ããæè¬æè¬ã
ãã¤ã³ãã¨ãã¦ã¯ã«ã©ã¼ãã¥ã¼ãè²ã¯èµ¤ç·éããããã6é調ã§ããã¤å®ã¯çééã§ãªãã¨ããç¹ã
...ãã®ææ¸ããç»åããESC+ASCIIã«å¤åããããã°ã©ã ã¯çééã§æ¸ãã¦ãã¾ã£ãæ°ãããorz
ãããã«ããæ°åã®ã¾ã¾ã ã¨ä½¿ãåæããããããªãã®ã§ãRGBã¨è²çªå·ã®å¤æããé¢æ°ãç¨æãã¾ãã
å
¨é¨1ããæ¸ãã®ã¯é¢åãªã®ã§äººæ§ã®ã³ã¼ããã±ãããããã±ãããã¤ã¤æ¸ãã¦ããã¾ãã
id:y_yanbe:20080611 ã«ããªãããããªã³ã¼ãããã£ãã®ã§æç²ãã¤ã¤å¾®å¦ã«æ¸ãæãã
è足çãªã®ã§y_yanbeæ°ã®ããã®ã¾ã¾ä½¿ã£ãæ¹ããããã¨ã
let s:colourcube_values = [ 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF ] let s:base16_values = [ [ 0x00, 0x00, 0x00 ] \ , [ 0xCD, 0x00, 0x00 ] \ , [ 0x00, 0xCD, 0x00 ] \ , [ 0xCD, 0xCD, 0x00 ] \ , [ 0x00, 0x00, 0xEE ] \ , [ 0xCD, 0x00, 0xCD ] \ , [ 0x00, 0xCD, 0xCD ] \ , [ 0xE5, 0xE5, 0xE5 ] \ , [ 0x7F, 0x7F, 0x7F ] \ , [ 0xFF, 0x00, 0x00 ] \ , [ 0x00, 0xFF, 0x00 ] \ , [ 0xFF, 0xFF, 0x00 ] \ , [ 0x5C, 0x5C, 0xFF ] \ , [ 0xFF, 0x00, 0xFF ] \ , [ 0x00, 0xFF, 0xFF ] \ , [ 0xFF, 0xFF, 0xFF ] ] function! s:abs( n ) if a:n > 0 return a:n else return (0 - a:n) end endfunction function! ESC2RGB( esc ) let esc = a:esc if esc < 16 return s:base16_values[a:esc] endif let esc = esc - 16 if esc < 216 let r = s:colourcube_values[(esc / 36) % 6] let g = s:colourcube_values[(esc / 6) % 6] let b = s:colourcube_values[esc % 6] return [r,g,b] endif let esc = esc - 216 if esc < 24 let y = 8 + esc * 10 return [y,y,y] endif let esc = esc - 24 echom "unknown esc code: " (esc+256) return endfunction let s:esc2rgbDict = {} for i in range( 0, 255 ) let s:esc2rgbDict[i] = ESC2RGB(i) endfor function! RGB2ESC( rgb ) let rgb = a:rgb if rgb[0] ==? "#" let rgb = rgb[1:] endif if strlen( rgb ) == 6 let r = str2nr(rgb[0] . rgb[1], 16 ) let g = str2nr(rgb[2] . rgb[3], 16 ) let b = str2nr(rgb[4] . rgb[5], 16 ) elseif strlen( rgb ) == 3 let r = str2nr(rgb[0] . rgb[0], 16 ) let g = str2nr(rgb[1] . rgb[1], 16 ) let b = str2nr(rgb[2] . rgb[2], 16 ) else echom "format error for: " . a:rgb return endif let mindiff = 20 let diff = 0xff * 3 let index = 0 for i in range( 0, 255 ) let d = s:abs( s:esc2rgbDict[i][0] - r ) \ + s:abs( s:esc2rgbDict[i][1] - g ) \ + s:abs( s:esc2rgbDict[i][2] - b ) if d < mindiff return i elseif d < diff let diff = d let index = i endif endfor return index endfunction
å
ã®æ¹ã§ã¯èª¤å·®ãæ±ããã®ã«äºä¹ã使ã£ã¦ããã®ã§ããããããªå³å¯ã«è·é¢æ±ããã§ãã¨æãæãã¦absã使ã£ã¦ã¾ãã
ãã¨dictionarysã使ã£ã¦ã¾ãããlistã¨ã©ã£ã¡ãæ©ãã®ãã*1ã
s:base16_valuesã¯ãªããå¾®å¦ã«å¤ã調æ´ããã¦ããã®ã§ãããããã¯ä½¿ã£ã¦ããã¿ã¼ããã«ã«ããããã°ããã®ããªï¼
å¤æ´ç¹ã¨ãã¦ã¯å
ã«æããabsã¨dictionarysã®ä»ãrgbããã®å¤æã§ã¯#rrggbbã®ä»ãrrggbbã#rgbãrgbã許容ã
ãã¨ãmindiffã¨ãã¦å¦¥åãã誤差ã追å ã
ããã¦éãã³ã¼ãã§ã¯ãªãã®ã§mindiffã¯0ã§ãããããã
ã¡ãªã¿ã« mindiff = 20 ã¯çµæ§ã§ããã§ãã ã«ã©ã¼ãã¥ã¼ãè²ã®é調ã®å·®ã40ãªã®ã§ãã®ååã使ã£ã¦ããã®ã§ããã
ä¾ãã°ã°ã¬ã¼ã¹ã±ã¼ã«ã®245ã¯#8A8A8Aãªã®ã§ãããRGBãããã3çªç®ã®é調ãã¤ã¾ããè²çªå·16+2*36+2*6+2=102ãã#878787ã¨ã#8A8A8Aã¨ããªãè¿ãããã®èª¤å·®ã¯9ã§ã#8A8A8Aã¯ã´ã£ããããè²çªå·ãããã«ããããããã245ã使ãããã«102ã使ããã¾ãã
ã¾ããã©ãã赤ç·éãããã6é調ãªãã ãããã»ã©æ°ã«ãªãæ§ãªèª¤å·®ã§ã¯ãªãããªãã¨ã
使ãæ¹ã¨ãã¦ã¯ :exe "highlight LineNr ctermfg=" . RGB2ESC( "#ff0000" ) ã®ããã«ã³ãã³ãã©ã¤ã³ã§ä½¿ãã»ãã
ä¾ãã°$VIMRUNTIME/syntax/xpm.vimã
--- xpm.vim.backup 2009-08-12 16:06:44.000000000 +0900 +++ xpm.vim 2009-08-12 16:25:11.000000000 +0900 @@ -18,7 +18,7 @@ syn region xpmComment start="/\*" end="\*/" contains=xpmTodo syn region xpmPixelString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@xpmColors -if has("gui_running") +if has("gui_running") || &t_Co == 256 let color = "" let chars = "" @@ -106,6 +106,7 @@ exe 'syn cluster xpmColors add=xpmColor'.n " if no color or color = "None" show background + if has("gui_running") if color == "" || substitute(color, '.*', '\L&', '') == 'none' exe 'hi xpmColor'.n.' guifg=bg' exe 'hi xpmColor'.n.' guibg=NONE' @@ -113,6 +114,15 @@ exe 'hi xpmColor'.n." guifg='".color."'" exe 'hi xpmColor'.n." guibg='".color."'" endif + else + if color == "" || substitute(color, '.*', '\L&', '') == 'none' + exe 'hi xpmColor'.n.' ctermfg=black' + exe 'hi xpmColor'.n.' ctermbg=NONE' + elseif color !~ "'" + exe 'hi xpmColor'.n." ctermfg='".RGB2ESC( color )."'" + exe 'hi xpmColor'.n." ctermbg='".RGB2ESC( color )."'" + endif + endif let n = n + 1 else break " no more color string
ã¿ããã«ãµã¯ã£ã¨ããããã¦ãã¾ããªã©ããã¨ãgVimã¨åæ§xpmãè²ãè¦ãªããç·¨éã§ããããã¡ããã¾ãâª
åèã«ããã¦ããã ããid:y_yanbe:20080611ã§ã¯cssã®è²ããã¬ãã¥ã¼ãã¤ã¤ç·¨éãããã¨ãguifg/guibg=#rrggbbãªé¨åãcterm=RGB2ESC("#rrggbb")ã«ãã¦ãgui_runningã®ä»ã«&t_Co==256ãæ¡ä»¶ã«ä»ãå ããã ãã§vimã©ã¤ãããã便å©ã«ãªã£ã¦ããã¾ãï¼
enjoy! vim life!
*1:dictionarysã ã¨æ°åãæååã«å¤ããæéããããã