简体   繁体   English

在 mac 终端的 vim 语法高亮中启用斜体

[英]Enabling italics in vim syntax highlighting for mac terminal

I'd like to have vim display my comments in italics, and I understand I need to place我想让 vim 以斜体显示我的评论,我知道我需要放置

cterm=italic

in the在里面

hi Comment

line in the color.vim file I'm using.我正在使用的 color.vim 文件中的行。 This, however, is having no effect on the text display, which I suspect has to do with some Terminal.app setting, unless I'm misunderstanding the vim syntax.然而,这对文本显示没有影响,我怀疑这与某些 Terminal.app 设置有关,除非我误解了 vim 语法。 I'd appreciate if someone can show me how to enable this feature.如果有人能告诉我如何启用此功能,我将不胜感激。

Additionally, I am currently using the Monaco font, which does not have a separate italic file (however, the italic syntax-highlighting doesn't work for Consolas, Lucida, Bitstream Vera or other italic- or oblique-enabled fonts either).此外,我目前使用的是 Monaco 字体,它没有单独的斜体文件(但是,斜体语法突出显示不适用于 Consolas、Lucida、Bitstream Vera 或其他支持斜体或斜体的字体)。 Assuming that a solution exists for fonts with italics, do I have to jump through any further hoops to get Monaco working?假设存在针对斜体字体的解决方案,我是否必须跳过任何进一步的步骤才能使 Monaco 正常工作?

Thanks for any input.感谢您的任何输入。

EDIT:编辑:
I'm surprised I haven't gotten an answer yet;我很惊讶我还没有得到答案; this doesn't seem like it should be too difficult to do.这似乎并不难做到。 Maybe it is.也许是。 Alternatively, could someone explain why this would not be possible?或者,有人可以解释为什么这不可能吗?

As of OS X Sierra 10.12, the default terminal app supports italics;从 OS X Sierra 10.12 开始,默认终端应用程序支持斜体; however, the included version of ncurses contains xterm terminfo files that do not declare italic support (they do not define the sitm capability).但是,包含的 ncurses 版本包含不声明斜体支持的 xterm terminfo 文件(它们不定义sitm功能)。 To work around this in Vim, add the following to your vimrc file to define the terminal commands for enabling/disabling italics:要在 Vim 中解决这个问题,请将以下内容添加到您的 vimrc 文件中以定义用于启用/禁用斜体的终端命令:

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:或者,要在本地自定义语法突出显示以格式化斜体注释,请将以下内容添加到您的 vimrc 文件中:

highlight Comment cterm=italic

As of SnowLeopard, Terminal doesn't support the italic attribute (SGR, value 3).从 SnowLeopard 开始,终端不支持斜体属性(SGR,值 3)。 Feel free to file a request at http://bugreporter.apple.com .请随时在http://bugreporter.apple.com上提出请求。

Update: Italic support was added to Terminal in macOS Sierra 10.12.更新:斜体支持已添加到 macOS Sierra 10.12 中的终端。 Note that the xterm terminfo files included with that version of ncurses do not declare the italic sitm capability.请注意,该版本的 ncurses 中包含的 xterm terminfo 文件未声明斜体sitm功能。 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 的回答https://stackoverflow.com/a/53625973/754997或 cheon 的回答https://stackoverflow.com/a/48512956/754997中的特定于 vim 的解决方法,以创建声明sitm的 terminfo 文件。

Italic support was added to Terminal in macOS Sierra 10.12 (after this question was asked);斜体支持已添加到 macOS Sierra 10.12 中的终端(在提出此问题后); however, the xterm terminfo files included with that version of ncurses do not declare the italic sitm capability.但是,该版本的 ncurses 中包含的 xterm terminfo 文件未声明斜体sitm功能。 You can work around this by creating a local terminfo file that declares the capability and inherits whichever terminfo file you're currently using.您可以通过创建一个本地 terminfo 文件来解决此问题,该文件声明该功能并继承您当前使用的任何 terminfo 文件。

In the following instructions, use whatever name TERM is set to.在以下说明中,使用TERM设置的任何名称。 xterm-256color is the default used by Terminal's built-in default profiles. xterm-256color是终端内置默认配置文件使用的默认值。

Create a file named xterm-256color-italic.terminfo :创建一个名为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 .在您的终端中运行tic xterm-256-italic.terminfo ,它将生成一个文件~/.terminfo/78/xterm-256color-italic This file will be found by ncurses automatically when TERM is set to the file's name.TERM设置为文件名时,ncurses 将自动找到该文件。

To set TERM=xterm-256-italic for an individual Terminal profile:为单个终端配置文件设置TERM=xterm-256-italic

简介

or you can just replace /usr/share/terminfo/78/xterm-256color with ~/.terminfo/78/xterm-256color-italic或者您可以将/usr/share/terminfo/78/xterm-256color替换为~/.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:然后你可以在vim中找到斜体字体:

vim

Italics support is coming to the iTerm2 terminal app - it's in the nightly builds now. iTerm2 终端应用程序即将支持斜体- 现在在夜间构建中。 As mentioned in the enhancement request you need to configure the TERMINFO var correctly.如增强请求中所述,您需要正确配置TERMINFO var。

Konrad, don't know about Terminal.app, but italic is supported in a lot of different terminal emulators. Konrad,不知道 Terminal.app,但很多不同的终端仿真器都支持斜体。 urxvt, konsole, gnome-terminal come to mind. urxvt、konsole、gnome-terminal 浮现在脑海中。

You can't with the regular monaco-font it seems.您似乎不能使用常规的摩纳哥字体。

It seems that only MacVim enables the italics.似乎只有 MacVim 启用斜体。

Here这里

In my testing, adding set background= or set background=dark or set background=light to one's vimrc file does the trick, Even if I am using the default preinstalled xterm-256color terminfo with no italics information in it.在我的测试中,将set background=set background=darkset background=light添加到一个人的 vimrc 文件中就可以了,即使我使用的是默认预安装的 xterm-256color terminfo,其中没有斜体信息。 Nothing else works, even if I use xterm-256color-italic suggested in previous answers.即使我使用之前答案中建议的 xterm-256color-italic,其他任何方法都不起作用。

Complete solution, building on top previous answers is:完整的解决方案,建立在以前的答案之上是:

let &t_ZH="\e[3m"
let &t_ZR="\e[23m"
highlight Comment cterm=italic
set background=dark " or set background=light or set background=

I don't know why this is so, have asked a question to Vim devs .我不知道为什么会这样, 向 Vim 开发人员提出了一个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM