14

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?

9
  • 1
    Great question. I have no idea if it's even possible, though. Commented Dec 28, 2011 at 12:38
  • 2
    I wouldn't like it ... folded lines are not only highlighted, but highlighted differently (in their own category) exactly for the reason to make them easier to distinguish. Highlighting them as any other would just blend them in more. Commented Dec 28, 2011 at 13:54
  • @ldigas Given that folded lines (on OP's picture) have different background color I don't think this is an issue. Commented Dec 28, 2011 at 15:18
  • @KohányiRóbert - On the contrary, that is an additional difficulty. Because some of the syntax elements can blend in with the background, to which "they suppose" it is black. Commented Dec 28, 2011 at 16:03
  • @ldigas, I have no concerns about colored folds blending in more when folds are identified by a page-wide set of dashes, and I can jump through them with zj Commented Dec 28, 2011 at 16:14

1 Answer 1

4

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. :(

Sign up to request clarification or add additional context in comments.

1 Comment

I think we're choosing to interpret that differently. I read it as him saying the unindented line would remain unfolded (wrapping the fold line proper) and could perhaps serve as a makeshift fold heading for you, not that the fold line itself would somehow have highlighted text embedded within it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.