sponsor Vim development Vim logo Vim Book Ad

Indent Highlight : Yet another indentation (scope) highlighting

 script karma  Rating 0/0, Downloaded by 599  Comments, bugs, improvements  Vim wiki

created by
Andrey Tsiporukha
 
script type
indent
 
description
This plugin provides a function that will highlight (or remove
highlighting ) of the current scope and parent scope based on difference in
indentation. It can be very usefull for languages that use indentation to
define the scope ( python, rubby, etc. )

I wrote this script so that I could quickly restore visual stack when
coding in python. So for python I created the following mapping in my vimrc:

map <silent> <Leader>ih :call IHighlight( 1, "\^[[:space:]]*\\(def\\\\|class\\)[[:space:]]\\+" )<CR>
map <silent> <Leader>is :call IHighlight( 0, "\^[[:space:]]*\\(def\\\\|class\\)[[:space:]]\\+" )<CR>

which allows me by entering \ih (or \is) to highlihgt current scope along
with the parent scope and than by entering \ih (or \is) again remove the
highlighting

the difference between \ih and \is is that
the first one (\ih) will turn off all syntax highlighting untill indentation highlighting is active
the syntax highlighting will be turned back on when you enter \ih again turning the indentation highlighting off
the second one (\is) will apply indentation highlighting on top of existing syntax highlighting

one can extend this functionality and provide bindings for movement keys so
that highlighting follows the cursor position
 
install details
just drop it in your plugin directory and you can start using IHightlight function

For a specific language I would recommend to add specific mapping in your vimrc file
something like this:
map <silent> <Leader>ih :call IHighlight( 1, regexp )<CR>
or this:
map <silent> <Leader>is :call IHighlight( 0, regexp )<CR>
where regexp is the regexp that matches language specific scope identifiers such as "class", "method", "def" and etc. This really depends on the language.

For python I use these mappings:
map <silent> <Leader>ih :call IHighlight( 1, "\^[[:space:]]*\\(def\\\\|class\\)[[:space:]]\\+" )<CR>
map <silent> <Leader>is :call IHighlight( 0, "\^[[:space:]]*\\(def\\\\|class\\)[[:space:]]\\+" )<CR>
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
indent_highlight.vim 1.0 2008-07-26 7.0 Andrey Tsiporukha Initial upload
ip used for rating: 18.191.174.168

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github