Some home directory dot files to be installed into a new user home directory.
.. | ||
---|---|---|
autoload | Add "rainbow" plugin for colored parentheses | 2024-05-26 14:29:28 |
doc | Add "rainbow" plugin for colored parentheses | 2024-05-26 14:29:28 |
plugin | Add "rainbow" plugin for colored parentheses | 2024-05-26 14:29:28 |
README.md | Add "rainbow" plugin for colored parentheses | 2024-05-26 14:29:28 |
help you read complex code by showing diff level of parentheses in diff color !!
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.
:h ft
).Plug 'luochen1990/rainbow'
let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle
first, execute the following commands (for windows users, use ~/vimfiles
instead of ~/.vim
)
it clone https://github.com/luochen1990/rainbow.git
d rainbow
kdir -p ~/.vim/plugin ~/.vim/autoload
p plugin/* ~/.vim/plugin
p autoload/* ~/.vim/autoload
second, add the follow sentences to your .vimrc
or _vimrc
:
et g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle
third, restart your vim and enjoy coding.
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
\ }
\}
guifg
(:h highlight-guifg
), i.e. colors for gui interface, will be used in ordergui
(:h highlight-gui
), will be used in orderctermfg
(:h highlight-ctermfg
)cterm
(:h highlight-cterm
)step
part of parentheses
.start=/(/
, step=/,/
, stop=/)/
, fold
, contained
, containedin=someSynNames
, contains=@Spell
, see :h syntax
for more details. notice that the step
part is defined by this plugin so it is not described by the official vim doc.containedin=xxxFuncBody
, contains=@Spell
(or 'contains=@NoSpell') often appears here. this option is often used to solve 3rd-party-plugin-compatibility problems.*
for filetypes without separate configuration, value 0
means disable rainbow only for this type of files, value "default"
means keep the default shim for this filetype (notice: the default shim config will change between plugin version).['syn clear xxx']
to solve 3rd-party-plugin-compatibility problems.To get more advanced config examples, try to search throught this tag.
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.
after
mechanism to clear these syntax.parentheses_options
mechanism like 'containedin=xxx'
.parentheses_options
mechanism like 'contains=@Spell'
.parentheses_options
mechanism like 'contains=@NoSpell'
.synID
inside it to find which syntax name prefix it depends on, and use the syn_name_prefix
mechanism to solve it.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
**