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:
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:
I want to continue using foldmethod=indent
, if possible. Is there a way to get syntax highlights on fold summaries? Perhaps another python.vim
?
The command to enable syntax highlighting in vim is :syntax on , if you want it to be active everytime you launch vim, just add a line containing syntax on in your . vimrc file. maybe your vim doesn't have filetype detection enabled, try adding filetype on to your .
Vim comes with syntax highlighting for many popular languages, including Python, though it is not always the best one. There are several options to improve the default highlighting.
It maps alt+1 to fold the first python indent level (class definitions and functions), alt+2 to fold the second level (class methods), and alt+0 to unfold everything. It makes sure it only folds one level and doesn't fold any of the nested sub levels. You can still use za to toggle folding for the current block.
Syntax highlighting is a feature of text editors that are used for programming, scripting, or markup languages, such as HTML. The feature displays text, especially source code, in different colours and fonts according to the category of terms.
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. :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With