在 vim 折叠线中语法高亮 Python

发布于 2024-12-23 04:38:41 字数 1179 浏览 6 评论 0原文

我发现代码折叠可以帮助我更好地组织文件。因此,在我的 ~/.vimrc 的底部,我启用 vim默认情况下代码折叠

""Folding
set foldmethod=indent
set foldnestmax=2
nnoremap <space> za
vnoremap <space> zf
"set nofoldenable       "set this to disable folding on file open

这具有使用 SPACE 在光标处切换折叠的优点,或者如果它们开始惹恼我,我可以使用zR 展开一切。

然而,我也沉迷于语法突出显示。我使用 Dmitry Vasiliev 的 python.vim ,但它不会突出显示折叠行中的语法:

vim Folded, no syntaxhighlighting

缺少语法 时,突出显示 Field('id', type='integer', unique=True, notnull=True), 让我的眼睛感到困难

当我习惯看到突出显示颜色 寻找的是一个支持折叠摘要语法突出显示的 python.vim ...如果 Dmitry 这样做了,它会以绿色突出显示字符串,如下所示:

所需的折叠突出显示

如果可能的话,我想继续使用 foldmethod=indent。有没有办法在折叠摘要上获取语法突出显示?也许另一个python.vim

I have found that code-folding helps me organize my files better. Thus, at the bottom of my ~/.vimrc, I enable vim code folding by default:

""Folding
set foldmethod=indent
set foldnestmax=2
nnoremap <space> za
vnoremap <space> zf
"set nofoldenable       "set this to disable folding on file open

This has the advantages of using SPACE to toggle folds at the cursor, or if they start to annoy me I can use zR to unfold everything.

However, I'm also addicted to syntax highlighting. I use Dmitry Vasiliev's python.vim, but it doesn't highlight syntax in a fold line:

vim folded, no syntax highlighting

The lack of syntax highlighting for Field('id', type='integer', unique=True, notnull=True), makes it hard on my eyes when I'm used to seeing the highlight colors

What I'm looking for is a python.vim that supports syntax highlighting on a fold summary... if it Dmitry's did, it would highlight the strings in green something like this:

desired folding highlights

I want to continue using foldmethod=indent, if possible. Is there a way to get syntax highlights on fold summaries? Perhaps another python.vim?

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

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

发布评论

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

评论(1

情痴 2024-12-30 04:38:41

之前曾提出过这个问题,答案是这是不可能的,因为折叠标题实际上不是文件的一部分,因此永远不会被荧光笔扫描。 :(

This question was asked previously and the answer was that it's not possible since the fold headline is not actually part of the file, thus never gets scanned by the highlighter. :(

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