Home

Awesome

Rainbow Parentheses Improved

help you read complex code by showing diff level of parentheses in diff color !!

Description (这里有中文版)

As everyone knows, the most complex codes were composed of a mass of different kinds of parentheses (typically: lisp). This plugin will help you read these codes by showing different levels of parentheses in different colors. You can also find this plugin in www.vim.org.

lisp

lisp

html

html

more

What is improved ?

Referenced:

Install

install via Plug:

Plug 'luochen1990/rainbow'
let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle

install manually:

Configure

There is an example for advanced configuration, add it to your vimrc and edit it as you wish (just keep the format).

Note: you can remove these lines safely since they are all included by the source code).

let g:rainbow_conf = {
\	'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
\	'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
\	'guis': [''],
\	'cterms': [''],
\	'operators': '_,_',
\	'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\	'separately': {
\		'*': {},
\		'markdown': {
\			'parentheses_options': 'containedin=markdownCode contained', "enable rainbow for code blocks only
\		},
\		'lisp': {
\			'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'], "lisp needs more colors for parentheses :)
\		},
\		'haskell': {
\			'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/\v\{\ze[^-]/ end=/}/ fold'], "the haskell lang pragmas should be excluded
\		},
\		'vim': {
\			'parentheses_options': 'containedin=vimFuncBody', "enable rainbow inside vim function body
\		},
\		'perl': {
\			'syn_name_prefix': 'perlBlockFoldRainbow', "solve the [perl indent-depending-on-syntax problem](https://github.com/luochen1990/rainbow/issues/20)
\		},
\		'stylus': {
\			'parentheses': ['start=/{/ end=/}/ fold contains=@colorableGroup'], "[vim css color](https://github.com/ap/vim-css-color) compatibility
\		},
\		'css': 0, "disable this plugin for css files
\		'nerdtree': 0, "rainbow is conflicting with NERDTree, creating extra parentheses
\	}
\}

To get more advanced config examples, try to search throught this tag.

User Command

3rd Party Plugin Compatibility

You should notice that this plugin is very special, Vim plugins is expected to provide syntax definitions vertically, i.e. one filetype, one syntax definition set:

----------------------------------------------------
|      cpp       |      java       |    python     |
|                |                 |               |
| syn cppKeyword | syn javaKeyword | syn pyKeyword |
| syn cppFunc    | syn javaFunc    | syn pyLambda  |
| syn cppParen   | syn javaParen   | syn pyParen   |
| ...            | ...             | ...           |
----------------------------------------------------

But this plugin provide syntax definitions horizontally, i.e. parentheses syntax for all filetypes:

----------------------------------------------------
|      cpp       |      java       |    python     |
|                |                 |               |
| syn cppKeyword | syn javaKeyword | syn pyKeyword |
| syn cppFunc    | syn javaFunc    | syn pyLambda  |
| ...            | ...             | ...           |
----------------------------------------------------
|                     rainbow                      |
|                                                  |
| syn cppRainbow   syn javaRainbow   syn pyRainbow |
----------------------------------------------------

You can notice that, to provide rainbow parentheses, this plugin have to define it's own syntax rules, and these rules will overwrite the parentheses syntax provided by the filetype plugin.

It works well at most of the time, but in some special cases, when the parentheses syntax rule is depended somewhere else (e.g. indent, spell checking, nested syntax rules), the things depend on the original syntax rules will be broken.

This plugin has provide some mechanisms to solve the compatibility problems, and have provided default configurations to solve compatibility problems with the default vim syntax files.

But if this plugin is conflicted with some other plugins, you will probably have to solve them by yourself. First, you can search on this issue tag to find whether there is somebody else had the same problem and solved it. Second, you can read the following content about troubleshooting.

Troubleshooting

The following keymappings will help you to check the syntax name and definitions under the cursor, add them to your vimrc and restart vim:

nnoremap <f1> :echo synIDattr(synID(line('.'), col('.'), 0), 'name')<cr>
nnoremap <f2> :echo ("hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">")<cr>
nnoremap <f3> :echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')<cr>
nnoremap <f4> :exec 'syn list '.synIDattr(synID(line('.'), col('.'), 0), 'name')<cr>

Move your cursor to a parentheses and press the keys to use them.


**Rate this script if you like it, and I'll appreciate it and improve this plugin for you because of your support!

Just go to this page and choose Life Changing and click rate**