A Vim plugin to highlight custom patterns on any buffer (filetype whitelist/blacklist supported), for example highlight indentation, inactive window, word under the cursor or even user made Vim highlighting.
-
https://github.com/bimlas/vim-high (please star if you like it)
Note
|
It’s in beta version (API and defaults may change) while I don’t get enough response that everything works as expected. |
To try out, install in your preferred way, then enable a lighter by
:HighEnable <C-D>
.
To enable lighters by default, add the preferred ones to g:high_lighter
as a
dictionary in your .vimrc, like this:
let g:high_lighters = {
\ '_': { (1)
\ 'blacklist': ['help', 'qf', 'lf', 'vim-plug'], (2)
\ },
\ 'inactive_window': {}, (3)
\ 'indent': {'_hlgroupA': 'HighIndentA', '_hlgroupB': 'HighIndentB'}, (4)
\ 'long_line': {'hlgroup': 'DiffAdd'},
\ 'unite_directory': {},
\ 'your_custom_lighter': {'pattern': 'TODO\|NOTE', 'hlgroup': 'ErrorMsg'} (5)
\ }
-
The
_
key means these settings will affect every lighter, -
for example all of them will be disabled in these filetypes.
-
You can add predefined lighters, whose can be found in autoload/high/light/ directory.
-
To override the global settings, pass the lighter-specific ones in the dictionary.
-
You can create your own lighters as you want.
By default, every lighter in g:high_lighters
are enabled at Vim startup, but
passing 'enabled': 0
will disable it. To use the lighter, call :HighEnable
lighter
or :HighToggle lighter
.
The available configuration parameters can be found in plugin/high.vim
as g:high.defaults
. Options starting with double underscore
(__init_function
for example) are private and you shouldn’t override those.
See :help matchadd
for pattern
and priority
; :highlight
for
possible values of hlgroup
.
Some lighters have specific settings, starting with an underscore (_length
of long_line for example) are
lighter-specific, the underscore is used only to prevent conflicts with global
settings, but you can safely override those.
Do not fear to view the source files to get the possibilities, because there is no help file for the plugin, source codes and test files contains everything.
To define your own hlgroup
, take a look at :help highlight
. Here are the
highlight groups of the example config, place it to your .vimrc:
autocmd ColorScheme,VimEnter *
\ highlight! HighIndentA guibg=#002029 guifg=#063642 |
\ highlight! HighIndentB guibg=#003542 guifg=#063642
Some lighters are based on Vim settings, for example
indent uses shiftwidth
to highlight the
indentation. The highlighting will follow the change of it only on certain
events (jumping to another window, switching buffer, etc.). To apply the new
settings automatically, you have to write an autocommand in your .vimrc:
autocmd CursorHold *
\ let pos = winnr()
\ | windo call high#UpdateGroups()
\ | exe pos.'wincmd w'
It will update every lighter where the __update_function
is set.
For example, a very basic implentation of Valloric/vim-operator-highlight should looks like this:
let g:high_lighters = {
\ 'operator': { (1)
\ 'pattern': '[-?+|*;:,<>&|!~%=)({}.\[\]]', (2)
\ 'blacklist': ['help', 'markdown', 'qf', 'conque_term', 'diff', 'html', (3)
\ 'css', 'less', 'xml', 'sh', 'bash', 'notes', 'jinja'],
\ 'hlgroup': 'Error', (4)
\ }}
-
Add a name to the lighter (which is not in use),
-
define the pattern to match,
-
add whitelist/blacklist,
-
choose a hlgroup from the existing ones.
The plugin can be used in another plugins, for example if you want to colorize
files by extension in Netrw (:Explore
, :edit ./
), then you can do
something like this:
let g:high_lighters = {
\ 'netrw_yaml': {
\ 'whitelist': ['netrw'],
\ 'pattern': '\v^([|│] )*\zs\f+\.yml',
\ 'hlgroup': 'HighNetrwYaml',
\ },
\ 'netrw_asciidoc': {
\ 'whitelist': ['netrw'],
\ 'pattern': '\v^([|│] )*\zs\f+\.adoc',
\ 'hlgroup': 'HighNetrwAsciidoc',
\ }}
autocmd ColorScheme,VimEnter *
\ highlight! HighNetrwYaml guifg=#ae9400 |
\ highlight! HighNetrwAsciidoc guifg=#dd3a00
Note that ^([|│] )*
part is needed by tree view (most right picture on the
screenshot).