
A Definitive Guide to Enabling Italics in Vim and Tmux - zdw
https://rsapkf.netlify.com/blog/enabling-italics-vim-tmux
======
JdeBP
Unfortunately, this is not definitive. Here are a bunch of corrections, off
the top of my head:

* echo -e is not portable across shells, and even across versions of the same shell sometimes. The test output should be generated with printf. [https://unix.stackexchange.com/q/65803/5132](https://unix.stackexchange.com/q/65803/5132)

* The article erroneously says "If you don't see italicised foo above, then you need to add a custom terminfo." where what it should say is "If vim does not emit this control sequence", or it should have an intermediate example using tput in place of hardwired control sequences. A custom terminfo will not affect the echo/printf command of the raw control sequences _at all_.

* The sideswipe about "better terminal emulators" mentioning only 3 fashionable ones is not well-founded. In fact, _most_ terminal emulators (from XTerm to Konsole, including even recent VTE-based ones) support italicization. Supporting the boldface/roman/italics triad that has been in Unix document processing for approaching half a century is not a niche or novel thing.

* The xterm-256color entry in terminfo already has ritm= and sitm= capabilities (via xterm-base and ecma+italics). There's no need to make one's own from someone's file on GitHub. [https://invisible-island.net/ncurses/terminfo.ti.html#tic-xt...](https://invisible-island.net/ncurses/terminfo.ti.html#tic-xterm-256color)

* The correct terminal type for tmux in terminfo is tmux or tmux-256color, which again already have ritm and sitm (again via ecma+italics). There is no need for a "new entry called 'tmux'". One should already have been there for roughly 5 years now. [https://invisible-island.net/ncurses/terminfo.ti.html#tic-tm...](https://invisible-island.net/ncurses/terminfo.ti.html#tic-tmux-256color)

~~~
hyperpallium
I had italics in vim (TERM was xterm-256color), but not in tmux (TERM was
screen).

Added this to ~/.tmux.conf and it works:

    
    
      set -g default-terminal "xterm-256color"
    

BTW it matters to me when using vim as a markdown viewer (esp for github
readme.md).

~~~
JdeBP
That is the wrong thing to do. The correct terminal type for tmux is either
"tmux" or "tmux-256color".

Even "screen" and "screen-256color" are not perfectly correct descriptions of
tmux nowadays (italics actually being a case in point); and there is no
problem with importing a "tmux-256color" entry into a more-than-half-a-decade-
old terminfo database. The database structure lends itself both to copying
individual records and to having extra records in one's home directory.

You should not be using "xterm-" _anything_ with tmux, or with any terminal or
terminal emulator that is not actually XTerm. Indeed, this mis-use is called
out _right at the top_ of the tmux FAQ.

* [http://jdebp.uk./Softwares/nosh/guide/commands/TERM.xml#MIS-...](http://jdebp.uk./Softwares/nosh/guide/commands/TERM.xml#MIS-CONFIGURATION)

* [https://invisible-island.net/xterm/xterm.faq.html#other_vers...](https://invisible-island.net/xterm/xterm.faq.html#other_versions)

* [https://github.com/tmux/tmux/wiki/FAQ](https://github.com/tmux/tmux/wiki/FAQ)

------
tomsmeding
In case anyone thinks they're doing something equivalent by making a
screen-256color-italic terminfo with the right keys and making sure your
terminal uses that, but is then surprised that it doesn't work, the linked
tmux FAQ ie very important:

> As of tmux 2.1, if default-terminal is set to "screen" or matches " screen-*
> ", tmux will behave like screen and italics will be disabled.

This means that you _must_ use a terminfo name that doesn't start with
screen-*.

~~~
JdeBP
That's slightly misleading. _The applications that get directed to a "screen-
wibble" terminfo entry will behave as if they are running under screen_,
because there will be no terminfo ritm/sitm capabilities and they won't emit
any control sequences for specifying italics.

tmux's own behaviour does change, but that is secondary, and a bit of a bodge.
(The applications will emit what they think is _something else_ , but will end
up emitting the ECMA-48 code for italics, so tmux refuses to recognize it.)

------
Athas
I'm down with the hacking aspect here, but why would I want to render comments
in italics? Comments are often larger pieces of natural language, and there's
a reason we don't typeset our books in all-italics - it's harder to read.

~~~
zokier
There is also a reason why we don't typeset books in monospaced fonts, but oh
well...

~~~
laumars
Yup, because it's cheaper (more words per line / fewer pages).

You could argue it is easier to read (and better for the environment too) but
it wasn't that long ago when fixed width was the norm (typewriters, dot-matrix
printers, early micro-computers / mainframes, etc) and people read just fine.

~~~
cpach
Well, setting whole books in fixed-width has never been the norm.

Personally I find fixed-width very hard to read for regular text.

For example, compare these two documents:

[http://www.laputan.org/pub/papers/aim-349.pdf](http://www.laputan.org/pub/papers/aim-349.pdf)

[http://www.larcenists.org/Documentation/Documentation0.98/r7...](http://www.larcenists.org/Documentation/Documentation0.98/r7rs.pdf)

I know which one I prefer when it comes to typography and readability.

~~~
enriquto
In your example, I find the typewritten text to be very beautifully laid out.
The latex rendering is cluttered and uses a font which is too thin.

~~~
zeveb
Computer Modern was designed to be printed with ink presses, and so it assumes
a certain amount of running in the liquid. If it will be rendered solely on-
screen, it needs to be thickened slightly. Fortunately this is easy with
Metafont; unfortunately the default TeX installations don't do it.

------
carapace
This delights my inner nerd, but my outer curmudgeon is miffed: I've fallen
out of love with teletype-based UIs (not text-based UIs) and it now feels like
epic "turd polishing" taken to absurd lengths.

It's 2020, _italics_ shouldn't be hard eh?

------
emmelaich
The echo command check didn't work for me on MacOS, bash 3.2

This works

    
    
       printf  "\e[3m foo \e[23m\n"
    

Although, you could use the sequence '^vESC' for each '\e' with echo.

------
yamaneko
Mine only worked when I added [this][1]:

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

before `highlight Comment cterm=italic`.

I was recently wondering how I'd make some keywords italic, like VSCode, which
italicizes ` _self_.foo` and others in Python. This thread came at the right
time. I found this [post][2] that may help, in combination with OP.

[1]:
[https://stackoverflow.com/a/21077380/](https://stackoverflow.com/a/21077380/)

[2]:
[https://www.reddit.com/r/vim/comments/dgbvw4/how_can_i_have_...](https://www.reddit.com/r/vim/comments/dgbvw4/how_can_i_have_italic_keywords_etc_in_neovim_like/)

------
_bxg1
I'll file this under reasons I don't use arcane terminal editors. There are so
much better uses of my time.

------
djohnston
on a related note, can someone point me to a definitive guide for getting
clipboards to work between vim, tmux, and my local machine?

my workflow rn is ... suboptimal

~~~
alpaca128
You can set Vim to use the clipboard as default register, meaning all yank,
delete and paste operations will directly use the clipboard:

    
    
      set clipboard=unnamedplus
    

Although of course that won't work if vim runs in ssh.

Not sure about tmux, I found it too cumbersome when it comes to scrolling and
text selection, so I switched to dvtm some time ago(which has its own issues).

