在 vim 中高亮显示 python 代码块

发布于 2025-01-03 03:03:07 字数 345 浏览 4 评论 0原文

我想在 vim 中突出显示不同的缩进级别,这样我就可以更轻松地识别大块代码。我有一些合理的大型嵌套 for/while/with/try 块,并且很难识别 a am 进入的块,即光标之前有多少个“选项卡”。

有没有办法突出显示选项卡?

这就是我的想法:

try:
*   while True:
*   *   for foo in bar:
*   *   *   do()
*   if something:
*   *   done()
except bla:
*   exit()

其中 * 是特殊的背景颜色。

我还愿意采用任何其他方式来确定压痕级别。

I wanted to highlight different indentation levels in vim, so I could identify large blocks of code more easily. I have some reasonable large nested for/while/with/try blocks and it gets hard to identify the block a am into, i.e. how many 'tabs' I have before the cursor.

Is there a way to highlight tabs?

This is what I have in mind:

try:
*   while True:
*   *   for foo in bar:
*   *   *   do()
*   if something:
*   *   done()
except bla:
*   exit()

Where * would be a special background color.

I would also settle for any other way to identify the indentation levels.

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

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

发布评论

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

评论(2

吃颗糖壮壮胆 2025-01-10 03:03:07

Indent Guides vim 插件正是做这种突出显示的。我将它与 listchars 选项一起使用(正如阿卡指出的那样)。

The Indent Guides vim plug-in does exactly this kind of highlighting. I use it together with the listchars option (as Ackar pointed out).

会傲 2025-01-10 03:03:07

您可以使用 listchars 选项来显示特定字符​​(请参阅:help listchars)。

例如,如果您想显示选项卡,可以使用:

:set listchars=tab:*\     " Be careful : there is a space after the backslash
:set list

您还可以使用 SpecialKey 组的 highlight 属性更改突出显示颜色。

如果您在终端中使用 vim :

:highlight SpecialKey ctermfg=Cyan

请参阅 :helphighlight 了解更多信息。

您还可以检查 :runtime syntax/colortest.vim 以查看所有可用的颜色。

You can use the listchars options to display specifics characters (see :help listchars).

For example if you want to show tabs you could use :

:set listchars=tab:*\     " Be careful : there is a space after the backslash
:set list

You can also change the highlighting colors using the highlight property for the SpecialKey group.

If you use vim in a terminal :

:highlight SpecialKey ctermfg=Cyan

See :help highlight for more informations.

You can also check :runtime syntax/colortest.vim to see all the available colors.

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