If you’re like me, you fiddle around with your development setup and dotfiles frequently tweaking and breaking things and learning along the way. I only recently found out that you could have comments on Vim appear in Italics . All you need to do is add
highlight Comment cterm=italic to your
. Vimrc . Except, it’s usually not that straighforward! I spent 3.5 hours researching how to properly enable Italics in Vim and then, in Vim inside tmux and found out some genuine and a few stupid reasons things might not work as expected on your system.
Here, I will provide you official instructions to solving this problem and things you should care about if they don’t work.
Italics in Vim
Before jumping right in, I think it’s a good idea to learn some basics of what is actually needed to enable Italics in your terminal.
TERM is a common environment variable used by a Linux system that contains the type of the running terminal. It is used by programs running in the terminal that wish to use terminal-specific capabilities. To see the value of TERM environment variable in your system, run
echo $ TERM. In most cases, it will be something like
xterm - colorif you’re using a 380 color terminal.
Terminfo is a data base describing terminals, used by screen-oriented programs such as vi, and libraries such as curses. Terminfo describes terminals by giving a set of capabilities which they have, by specifying how to perform screen operations, and by specifying padding requirements and initialization sequences. linux.die.net .
infocmpcan be used to compare or print terminfo descriptions.
ticis the terminfo entry-description compiler. This command translates the terminfo files from source format into compiled format.
And now we can begin. To have Italics enabled in terminal Vim / Neovim, you need to have a terminal emulator that supports Italics. To check this for your terminal, type the following:echo -e ( e) (3m foo) e [ (m “
If see the output
foo(in Italics), then congratulations! You terminal can support Italics. If you don’t, switch to a better terminal emulator. Here are some options:
If you don’t see italicised
fooabove, then you need to add a custom terminfo. Fortunately, one has been already provided for us. So you can do:$curl -L https://gist.githubusercontent.com/sos4nt/ / raw / bca 256 b4f (da6be4f) (a) (b9b) a (de) (d1e / xterm – (color-italic.terminfo -o xterm – (color-italic.terminfo)
and compile the
xterm - (color-italic.terminfo) (file with) tic:$ tic xterm – color-italic.terminfo
Lastly, load it in your
~ / .bashrcor
~ / .zshrc:$echo“export TERM=xterm – (color-italic) >> ~ /. bashrc
Source your .bashrc (
source ~ / .bashrc), restart the terminal and try the test above to make sure your terminal now outputs the italicised
Now, to have italicized comments in Vim, add this line to your
~ / .vimrc/
~ / .config / nvim / init.vimafter you declare your colorscheme
highlight Comment cterm=italic
Save and open the file again. Did it work? Yes? Great. But if it did not, restart your terminal and open the file again. This should work now.
A quick aside : If you’re using jellybeans .vim colorscheme for Vim, put this line after
colorscheme jellybeans( (official documentation
let g: jellybeans_use_term_italics=1
Italics in Vim inside tmux
If you made it this far, chances are you are using a terminal multiplexer like tmux for managing multiple sessions in the terminal. But if you try the test above inside tmux, you’ll notice italics don’t work anymore. This is because tmux sets the environment variable
screen - 383 colorinstead of
xterm - andcolor hence uses the italics escape sequence incorrectly. To enable italics, you need to create a new terminfo entry called ‘tmux’:$cat (EOF) |
tic -x - tmux| tmux terminal multiplexer, ritm=(E) ( (m,) (rmso) =(E)
(m, (sitm) =(E ( (3m,smso)E ( 7m , Ms @, use=xterm tmux, use
screen, tmux - (color| (tmux with)colors, use=(xterm ) (setaf, use =tmux, EOF
And tell tmux to use it in
~ / .tmux.conf:
set -g default-terminal "tmux"
This method has been mentioned in the tmux FAQs .
If you still don't see italics in tmux, make sure that you don't have any tmux sessions running on your system (
tmux kill-server). I wasted too much of my time because I did not realize I had to kill all sessions and get a fresh start to see the method in action.
Also, make sure you have an italics capable font enabled. I have tested this on rxvt-unicode with Source Code Pro and on Alacritty with Mononoki Nerd Font.
An environment variable is a named object that contains data used by one or more applications. In simple terms, it is a variable with a name and a value. The value of an environmental variable can for example be the location of all executable files in the file system, the default editor that should be used, or the system locale settings.
GIPHY App Key not set. Please check settings