15

The beloved Solarized colour scheme seems to apply an italic face for comments, but when I am using it in vim in iTerm2, it does not.

So, everything including comments are displayed in Roman (normal) face. Even if I select the Menlo font, which has an italic face I can see in iTerm2's preferences window, the comments are rendered as Roman.

Together with the fact that comments are in light gray, and normal text in (not very bright) white, comments become rather difficult to distinguish from normal text.

To me this is a flaw in the otherwise great color scheme. I did some searching but the advice is old and do not solve the problem. I'm using OS X 10.6 Sierra on a MacBook Air.

2 Answers 2

36

You have to update your TERMINFO file.

Thanks to wincent's video and his github pages
Watch the video and look at his github pages, they're excellent.

I have the following note stored on my HD:

We can have italics in the terminal.

This works in iTerm as well as Terminal.

We have to adapt the terminfo database to tell it to display italics.

Create a plain text file which contains the following:

xterm-256color|xterm with 256 colors and italic,
  sitm=\E[3m, ritm=\E[23m,
  use=xterm-256color,

Save it as xterm-256color.terminfo.txt

Then execute the following command:

tic -o ~/.terminfo xterm-256color.terminfo.txt

This will create a ~/.terminfo/some_arbitrary_number/ directory, and inside that directory is a xterm-256color file.

What it does according to the manpage:

       The command tic translates a terminfo file from source format into com-
       piled  format.   The  compiled  format  is  necessary  for use with the
       library routines in ncurses(3X).

       The results are  normally  placed  in  the  system  terminfo  directory
       /usr/share/terminfo.  There are two ways to change this behavior.

       First, you may override the system default by setting the variable TER-
       MINFO in your shell environment to a valid (existing) directory name.

       Secondly, if tic cannot get access to /usr/share/terminfo or your  TER-
       MINFO  directory,  it  looks for the directory $HOME/.terminfo; if that
       directory exists, the entry is placed there.

       Libraries that read terminfo entries are expected to check for  a  TER-
       MINFO  directory first, look at $HOME/.terminfo if TERMINFO is not set,
       and finally look in /usr/share/terminfo.

       -o dir   Write  compiled  entries to given directory.  Overrides the TER-
                MINFO environment variable.

So with the given command we are writing a new terminfo entry in the hidden ~/.terminfo directory. It takes the capabilities of the existing xterm-256color entry (from /usr/share/terminfo/) and adds italics mode to it.

To check that the terminal does the right thing:

  • with fish:

    echo (tput sitm)'italics' (tput ritm) (tput smso)'standout'(tput rmso)
    
  • with bash or zsh:

    echo `tput sitm`italics`tput ritm` `tput smso`standout`tput rmso`
    

I guess at the moment most vim terminal colorschemes don't set italic as a style. To check this do:
:hi Comment if the reply contains cterm=italic you're done. If not add highlight Comment cterm=italic to your vimrc (below setting your colorscheme).

Addendum for tmux

tmux uses its own terminfo files, they also need to be updated to use italics.

  1. create a tmux.terminfo.txt file which contains

tmux|tmux terminal multiplexer, sitm=\E[3m, ritm=\E[23m, smso=\E[7m, rmso=\E[27m, use=screen,

  1. create a tmux-256color.terminfo.txt file which contains

tmux-256color|tmux with 256 colors, sitm=\E[3m, ritm=\E[23m, smso=\E[7m, rmso=\E[27m, use=screen-256color,

and run the tic command.

tic -o ~/.terminfo tmux-256color.terminfo.txt
and
tic -o ~/.terminfo tmux.terminfo.txt

11
  • 2
    Wow! After doing these, with the test you gave, "italic" and "standout" both works, but opening a cpp in vim does not render comments italic. Is this Solarized's problem? Commented Jan 3, 2017 at 17:37
  • 2
    Oh! I notice that MacVim's GUI (i.e. the separate window that prompts) can display italic fonts, but if opened in the terminal (with mvim -v), it cannot. Is is normal? Commented Jan 3, 2017 at 17:51
  • 2
    If you do in vim: :hi Comment does it say cterm=italic? If not Solarized doesn't set this. You can do this in your vimrc with highlight Comment cterm=italic
    – PeterVP
    Commented Jan 3, 2017 at 21:10
  • 3
    IT WORKS!!!! MY COMMENTS ARE ITALIC NOW!!! I will tell the world the good news!!! (I always thought Solarized set this by default) Commented Jan 4, 2017 at 6:01
  • In my machine (arch linux), cterm=standout displayed italics, and the command above could only display the word standout but in italics.
    – user120098
    Commented Mar 9, 2017 at 9:59
0

In addition to updating my TERMINFO, I had to make two other changes.

  1. Edit .vim/colors/solarized.vim as recommended in Solarized #120 to replace lines 137-157 with the following:

     if has("gui_running") || ( has("unix") && system("tput sitm") == "\033[3m" )
         let s:terminal_italic=1
     else
         let s:terminal_italic=0
     endif
    
  2. Edit .vimrc to add the following lines using <Ctrl-v><Esc> to enter the ^[ characters.

     " Enable italics
     set t_ZH=^[[3m
     set t_ZR=^[[23m
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .