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.
Add the text, “syntax on” anywhere in the file to enable syntax highlighting permanently for vim editor. Save and close the file by typing ':x'. For disabling the feature, just re-open . vimrc file, change the text “syntax on” to “syntax off” and save the file.
The Indent Guides vim plug-in does exactly this kind of highlighting. I use it together with the listchars
option (as Ackar pointed out).
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.
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