在 Mac 终端的 vim 语法突出显示中启用斜体

发布于 2024-08-03 00:48:59 字数 438 浏览 6 评论 0原文

我想让 vim 以斜体显示我的注释,并且我知道我需要将其放在

cterm=italic

hi Comment

正在使用的 color.vim 文件中。然而,这对文本显示没有影响,我怀疑这与某些 Terminal.app 设置有关,除非我误解了 vim 语法。如果有人能告诉我如何启用此功能,我将不胜感激。

此外,我目前使用的是 Monaco 字体,它没有单独的斜体文件(但是,斜体语法突出显示不适用于 Consolas、Lucida、Bitstream Vera 或其他支持斜体或斜体的字体)。假设存在斜体字体的解决方案,我是否需要跳过任何进一步的障碍才能让 Monaco 工作?

感谢您的任何意见。

编辑:
我很惊讶我还没有得到答复;这似乎并不难做到。也许是的。或者,有人可以解释为什么这不可能是可能的吗?

I'd like to have vim display my comments in italics, and I understand I need to place

cterm=italic

in the

hi Comment

line in the color.vim file I'm using. 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. 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). Assuming that a solution exists for fonts with italics, do I have to jump through any further hoops to get Monaco working?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

゛清羽墨安 2024-08-10 00:48:59

从 OS X Sierra 10.12 开始,默认终端应用程序支持斜体;但是,包含的 ncurses 版本包含未声明斜体支持的 xterm terminfo 文件(它们未定义 sitm 功能)。要在 Vim 中解决此问题,请将以下内容添加到 vimrc 文件中,以定义用于启用/禁用斜体的终端命令:

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

然后确保您使用的字体支持斜体,并且您的颜色方案在某些语法部分包含斜体。或者,要在本地自定义语法突出显示以将注释格式设置为斜体,请将以下内容添加到 vimrc 文件中:

highlight Comment cterm=italic

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
潜移默化 2024-08-10 00:48:59

从 SnowLeopard 开始,终端不支持斜体属性(SGR,值 3)。请随时访问 http://bugreporter.apple.com 提交请求。

更新:macOS Sierra 10.12 中的终端添加了斜体支持。请注意,该版本的 ncurses 中包含的 xterm terminfo 文件未声明斜体 sitm 功能。请参阅 Bahman Eslami 的答案 https://stackoverflow.com/a/53625973/754997 或 cheon 的答案中特定于 vim 的解决方法https://stackoverflow.com/a/48512956/754997 用于创建声明 sitm.

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.

时光瘦了 2024-08-10 00:48:59

macOS Sierra 10.12 中的终端添加了斜体支持(在提出这个问题之后);但是,该版本的 ncurses 中包含的 xterm terminfo 文件未声明斜体 sitm 功能。您可以通过创建一个本地 terminfo 文件来解决此问题,该文件声明该功能并继承您当前使用的 terminfo 文件。

在以下说明中,使用 TERM 设置的任何名称。 xterm-256color 是终端内置默认配置文件使用的默认值。

创建一个名为 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,

在终端中运行 tic xterm-256-italic.terminfo,它将生成一个文件 ~/. terminfo/78/xterm-256color-italic。当 TERM 设置为文件名时,ncurses 将自动找到该文件。

要为单个终端配置文件设置TERM=xterm-256-italic

profiles

或者您可以替换 /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

然后你可以在 vim 中找到斜体字体:

vim

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:

profiles

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:

vim

初熏 2024-08-10 00:48:59

iTerm2 终端应用即将斜体支持 - 它位于现在每晚构建。正如增强请求中提到的,您需要正确配置 TERMINFO var。

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.

故人爱我别走 2024-08-10 00:48:59

Konrad,不知道 Terminal.app,但很多不同的终端模拟器都支持斜体。
我想到了 urxvt、konsole、gnome-terminal。

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.

泪意 2024-08-10 00:48:59

您似乎不能使用常规的摩纳哥字体。

似乎只有 MacVim 启用斜体。

这里

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

It seems that only MacVim enables the italics.

Here

染柒℉ 2024-08-10 00:48:59

在我的测试中,将 setbackground=setbackground=darksetbackground=light 添加到 vimrc 文件即可解决问题!即使我使用默认预安装的 xterm-256color terminfo,其中没有斜体信息!即使我使用之前答案中建议的 xterm-256color-italic,其他任何方法都不起作用。

完整的解决方案,建立在之前的答案之上,是:

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

我不知道为什么会这样,已经问了 向 Vim 开发人员提问

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! Nothing else works, even if I use xterm-256color-italic suggested in previous answers.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文