sponsor Vim development Vim logo Vim Book Ad

otf.vim : On-The-Fly coloring of patterns, Inspired by MultipleSearch.vim

 script karma  Rating 23/8, Downloaded by 2773  Comments, bugs, improvements  Vim wiki

created by
Robert KellyIV
script type
Inspired by MultipleSearch.vim vimscript #479

This plugin will allow you to highlight a specific search pattern with a specific (pre made) highlight group, and allows you to easily redefine the search pattern and empty a specific pattern. There are 8 possible simultaneous highlight patterns currently available and the script should be easy to modify to add more, etc. The highlight groups are via syntax highlighting and as such your VIM needs +syntax feature.

There are 2 commands, 1 to clear all highlighting, 1 to manipulate individule color groups.
:OTFReset -- to clear all highlighting done by this script. (think :noh) This can probably be shortened to :OTFR on the command line.

:OTF -- takes a count (line number position) to specify the color group to use (1-8). blank string clears highlighting for the specified color group, while the bang (:OTF!) denotes that the specifed string should be treated as a keyword (think register), see below:

Use Like So:
    Highlight Current Word Under The Cursor:
    :1OTF <c-r><c-w>
    :1OTF! w
    Highlight Current Search Pattern:
    :1OTF <c-r>/
    :1OTF! /
    Use A Pattern From A Register:
    :1OTF <c-r>"
    :1OTF! "
    Just Type The Pattern In Manually:
    :1OTF \cotf\d
    Turn Off Coloring For The First Highlight Group:
    Turn Off Coloring For The Second Highlight Group: (etc.)
    Turn Off Coloring For All Groups:
    Which can probably be shortened to:

You can override the default highlight group color definitions by simply defining your own highlight groups for feralotf# (where # is a number from 1 to 8) for example place this in your .vimrc (or color file, etc.):
" {{{ OVERRIDE On the fly highlight groups.
hi feralotf1 guifg=#4682B4 guibg=Linen
hi feralotf2 guifg=Linen
hi feralotf3 guifg=Linen guibg=azure4
hi feralotf4 guifg=Linen guibg=PaleGreen4
" }}}
install details
To Install:
    Drop into plugin directory.
To Uninstall
    Remove from plugin directory
To Test Drive:
    Load file into vim and source it (:source %)
    :OTF \cotf\d
    You should see all occurrences of `otf#` where # is a number as specified by \d highlighted as white text on red background.
    You can turn off the highlighting with
    If you would like to see another color, use this format: :#OTF <pattern> where # is a number between 1 and 8 and <pattern> is what you want to color.

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
otf.vim 0.31 2004-06-15 6.0 Robert KellyIV Refinement of :OTF -- just bank (with no keyword) will clear the specified group.
Improvement: ':[#]OTFG[!] <register>' which will copy contents of specifed group to specified register.This means that you can ":2OTFG y" to copy the search pattern used by highlight group 2 into register y.
otf.vim 0.21 2003-05-07 6.0 Robert KellyIV Improvement: As per a suggestion from Mathieu CLABAUT the feralotf# highlight groups now use the default keyword, This allows you to override these default colors easily.
otf.vim 0.2 2003-05-03 6.0 Robert KellyIV Small update: converted :OTF1-8 into :OTF which takes a count (line number position) and takes optional bang to specify string as a keyword (think register)
Keywords are:
    (w) cword,                     expand("<cword>")
    (W) \<cword\>                  "\\<".expand("<cword>")."\\>"
    (") unnamed register           @@
    (/) current search string      @/
i.e. ":2OTF! /" (bang) will pull in the current search string and color it in color group2, while ":2OTF /" (no bang) will color '/' in color group2

Original :OTF1-8 commands updated to bang style but commented out (just in case anyone liked that method)
otf.vim 0.1 2003-05-02 6.0 Robert KellyIV Initial upload
ip used for rating:

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.