altercation / vim-colors-solarized

precision colorscheme for the vim text editor
http://ethanschoonover.com/solarized
6.58k stars 1.76k forks source link

enable italics in iTerm2 #120

Open AprilArcus opened 9 years ago

AprilArcus commented 9 years ago

Italics are now supported in iTerm2, if the user supplies an emended terminfo file. See Enabling italic fonts in iTerm2, tmux, and vim by Alex Pierce for a detailed walkthrough.

Right now, vim-colors-solarized/colors/solarized.vim lines 137-157 employ an if/else tree to determine compatibility with italics by testing against a hard-coded list of known-compatible terminal emulators:

" Terminals that support italics
let s:terms_italic=[
            \"rxvt",
            \"gnome-terminal"
            \]
" For reference only, terminals are known to be incomptible.
" Terminals that are in neither list need to be tested.
let s:terms_noitalic=[
            \"iTerm.app",
            \"Apple_Terminal"
            \]
if has("gui_running")
    let s:terminal_italic=1 " TODO: could refactor to not require this at all
else
    let s:terminal_italic=0 " terminals will be guilty until proven compatible
    for term in s:terms_italic
        if $TERM_PROGRAM =~ term
            let s:terminal_italic=1
        endif
    endfor
endif

I think a more general approach would be to shell out to tput and test for a correct sitm entry:

if has("gui_running") || ( has("unix") && system("tput sitm") == "\033[3m" )
    let s:terminal_italic=1
else
    let s:terminal_italic=0
endif

I think this should cover all the bases.

HerringtonDarkholme commented 8 years ago

+1 for this. I wonder whether this repository is actively maintained any more. Maybe forking it is a good choice.

antoineco commented 6 years ago

That's a great solution :+1:

The t_ZH terminal option is derived from the termcap value, and should also be fairly reliable:

if has("gui_running") || ( has("unix") && &t_ZH ==# "\033[3m" )
    let s:terminal_italic=1
else
    let s:terminal_italic=0
endif
mefryar commented 3 years ago

Thanks, @AprilArcus! In addition to implementing your edit to .vim/colors/solarized.vim, I also had to follow this Gist and add these two lines to my .vimrc, using <Ctrl-v><Esc> to enter ^[:

set t_ZH=^[[3m
set t_ZR=^[[23m