Enabling italics in vim syntax highlighting for mac terminal

ε祈祈猫儿з 提交于 2019-12-05 02:36:08
Ben Stiglitz

As of SnowLeopard, Terminal doesn’t support the italic attribute (SGR, value 3). Feel free to file a request at http://bugreporter.apple.com.

Update: Italic support was added to Terminal in macOS Sierra 10.12. Note that the xterm terminfo files included with that version of ncurses do not declare the italic sitm capability. See the vim-specific workaround in Bahman Eslami’s answer https://stackoverflow.com/a/53625973/754997 or cheon’s answer https://stackoverflow.com/a/48512956/754997 for creating a terminfo file that declares sitm.

Bahman Eslami

As of OS X Sierra 10.12, the default terminal app supports italics; however, the included version of ncurses contains xterm terminfo files that do not declare italic support (they do not define the sitm capability). To work around this in Vim, add the following to your vimrc file to define the terminal commands for enabling/disabling italics:

let &t_ZH="\e[3m"
let &t_ZR="\e[23m"

Then make sure the font you use supports italics and also your colorscheme contains italic for some syntax parts. Or, to customize the syntax highlighting locally to format comments in italics, add the following to your vimrc file:

highlight Comment cterm=italic
cheon

Italic support was added to Terminal in macOS Sierra 10.12 (after this question was asked); however, the xterm terminfo files included with that version of ncurses do not declare the italic sitm capability. You can work around this by creating a local terminfo file that declares the capability and inherits whichever terminfo file you’re currently using.

In the following instructions, use whatever name TERM is set to. xterm-256color is the default used by Terminal’s built-in default profiles.

Create a file named xterm-256color-italic.terminfo:

# A xterm-256color based TERMINFO that adds the escape sequences for italic.
xterm-256color-italic|xterm with 256 colors and italic,
  sitm=\E[3m, ritm=\E[23m,
  use=xterm-256color,

Run tic xterm-256-italic.terminfo in your terminal, it will generate a file ~/.terminfo/78/xterm-256color-italic. This file will be found by ncurses automatically when TERM is set to the file’s name.

To set TERM=xterm-256-italic for an individual Terminal profile:

or you can just replace /usr/share/terminfo/78/xterm-256color with ~/.terminfo/78/xterm-256color-italic

sudo cp /usr/share/terminfo/78/xterm-256color /usr/share/terminfo/78/xterm-256color-bak
sudo cp ~/.terminfo/78/xterm-256-color-italic /usr/share/terminfo/78/xterm-256color

Then you can find italics font in vim:

Italics support is coming to the iTerm2 terminal app - it's in the nightly builds now. As mentioned in the enhancement request you need to configure the TERMINFO var correctly.

Konrad, don't know about Terminal.app, but italic is supported in a lot of different terminal emulators. urxvt, konsole, gnome-terminal come to mind.

You can't with the regular monaco-font it seems.

It seems that only MacVim enables the italics.

Here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!