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?

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
  • 1
    Great question. I have no idea if it's even possible, though. – Daniel Roseman Dec 28 '11 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. – Rook Dec 28 '11 at 13:54
  • @ldigas Given that folded lines (on OP's picture) have different background color I don't think this is an issue. – Kohányi Róbert Dec 28 '11 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. – Rook Dec 28 '11 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` – Mike Pennington Dec 28 '11 at 16:14
  • Mike, just sayin'. In any case, I don't know whether what you are asking is possible. – Rook Dec 28 '11 at 16:19
  • @KohányiRóbert, the reason the lines in my picture have a grey background color is because I manually highlighted them in vim with shift-V for emphasis between the pictures. The folds themselves are denoted by `+-- X lines: ... ------------------------------` – Mike Pennington Dec 28 '11 at 16:21
  • @MikePennington I see. /me not heavy _folder_. :) However if one is able to highlight parts of a fold it's quite likely he/she could manipulate its background color too—separately from the _normal_ background (in a way that there won't be blending). – Kohányi Róbert Dec 28 '11 at 16:46
  • @KohányiRóbert, correct. For instance, you can change the background highlighting of a fold with `:highlight Folded term=standout ctermfg=darkgrey ctermbg=white`. The aforementioned example would give folds a white background with grey lettering – Mike Pennington Dec 28 '11 at 17:08

1 Answers1

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

Community
  • 1
  • 1
Spencer
  • 665
  • 3
  • 8
  • 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. – Spencer Dec 31 '11 at 04:27