Skip to content

Vim plugin: All-in-one highlighter, highlight custom pattern like indentation, inactive window, word under the cursor

License

Notifications You must be signed in to change notification settings

bimlas/vim-high

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vim-High: all-in-one Vim highlighter plugin

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.

Travis CI License

Note

It’s in beta version (API and defaults may change) while I don’t get enough response that everything works as expected.

Philosophy of the plugin
Vim-High in action, showing the example config

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)
\ }
  1. The _ key means these settings will affect every lighter,

  2. for example all of them will be disabled in these filetypes.

  3. You can add predefined lighters, whose can be found in autoload/high/light/ directory.

  4. To override the global settings, pass the lighter-specific ones in the dictionary.

  5. You can create your own lighters as you want.

Override default settings

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.

Custom colors

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

Dynamic update of highlighters

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.

Examples of user-defined highlight in Vim

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)
\ }}
  1. Add a name to the lighter (which is not in use),

  2. define the pattern to match,

  3. add whitelist/blacklist,

  4. choose a hlgroup from the existing ones.

Vim Netrw filetype coloring

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).

Vim Netrw filetype coloring

About

Vim plugin: All-in-one highlighter, highlight custom pattern like indentation, inactive window, word under the cursor

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published