让你的代码呈现阶梯色彩,代码展示的好东西

1,467 阅读3分钟
原文链接: github.com

rainbow_levels.vim

A different approach to code highlighting.

Join the chat License: MIT Tweet

This plugin highlights your code by indentation level, instead of language syntax. It is specially useful when dealing with deeply nested code, callback hells, etc.

Screenshot

Rainbow Levels Screenshot

github.com/jquery/jque…

Usage

This plugin exposes three self-explanatory commands:

  • :RainbowLevelsToggle
  • :RainbowLevelsOn
  • :RainbowLevelsOff

And you can use them in a variety of ways, for example:

" Creating a mapping to turn it on and off:
map <leader>l :RainbowLevelsToggle<cr>

" Or automatically turning it on for certain file types:
au FileType javascript,python,php,xml,yaml :RainbowLevelsOn

In addition to the commands mentioned above, it also exposes a global variable g:rainbow_levels that can be overridden to change the highlight color of each level.

Themes

It looks much better if the colors match the current colorscheme, so to save you some time, here is a list of g:rainbow_levels values for some popular colorschemes.

Jellybeans

let g:rainbow_levels = [
    \{'ctermfg': 121, 'guifg': '#65c254'},
    \{'ctermfg': 81,  'guifg': '#8fbfdc'},
    \{'ctermfg': 11,  'guifg': '#8197bf'},
    \{'ctermfg': 14,  'guifg': '#c6b6ee'},
    \{'ctermfg': 13,  'guifg': '#cf6a4c'},
    \{'ctermfg': 121, 'guifg': '#ffb964'},
    \{'ctermfg': 7,   'guifg': '#e8e8d3'},
    \{'ctermfg': 14,  'guifg': '#888888'}]



Zenburn

let g:rainbow_levels = [
    \{'ctermfg': 108, 'guifg': '#7f9f7f'},
    \{'ctermfg': 116, 'guifg': '#8cd0d3'},
    \{'ctermfg': 109, 'guifg': '#9fafaf'},
    \{'ctermfg': 174, 'guifg': '#cc9393'},
    \{'ctermfg': 223, 'guifg': '#ffd7a7'},
    \{'ctermfg': 228, 'guifg': '#efef8f'},
    \{'ctermfg': 230, 'guifg': '#f0efd0'},
    \{'ctermfg': 240, 'guifg': '#5b605e'}]



Solarized

let g:rainbow_levels = [
    \{'ctermfg': 2, 'guifg': '#859900'},
    \{'ctermfg': 6, 'guifg': '#2aa198'},
    \{'ctermfg': 4, 'guifg': '#268bd2'},
    \{'ctermfg': 5, 'guifg': '#6c71c4'},
    \{'ctermfg': 1, 'guifg': '#dc322f'},
    \{'ctermfg': 3, 'guifg': '#b58900'},
    \{'ctermfg': 8, 'guifg': '#839496'},
    \{'ctermfg': 7, 'guifg': '#586e75'}]



Dracula

let g:rainbow_levels = [
    \{'ctermfg': 84,  'guifg': '#50fa7b'},
    \{'ctermfg': 117, 'guifg': '#8be9fd'},
    \{'ctermfg': 61,  'guifg': '#6272a4'},
    \{'ctermfg': 212, 'guifg': '#ff79c6'},
    \{'ctermfg': 203, 'guifg': '#ffb86c'},
    \{'ctermfg': 228, 'guifg': '#f1fa8c'},
    \{'ctermfg': 15,  'guifg': '#f8f8f2'},
    \{'ctermfg': 231, 'guifg': '#525563'}]



Monokai

let g:rainbow_levels = [
    \{'ctermfg': 2, 'guifg': '#a6e22e'},
    \{'ctermfg': 6, 'guifg': '#66d9ef'},
    \{'ctermfg': 4, 'guifg': '#ae81ff'},
    \{'ctermfg': 5, 'guifg': '#f92672'},
    \{'ctermfg': 1, 'guifg': '#fd971f'},
    \{'ctermfg': 3, 'guifg': '#f4bf75'},
    \{'ctermfg': 7, 'guifg': '#f8f8f2'},
    \{'ctermfg': 0, 'guifg': '#75715e'}]



Birds of Paradise

let g:rainbow_levels = [
    \{'ctermfg': 185, 'guifg': '#d9d762'},
    \{'ctermfg': 109, 'guifg': '#86b4bb'},
    \{'ctermfg': 67,  'guifg': '#6c99bb'},
    \{'ctermfg': 98,  'guifg': '#8856d2'},
    \{'ctermfg': 203, 'guifg': '#ef5d32'},
    \{'ctermfg': 215, 'guifg': '#efac32'},
    \{'ctermfg': 188, 'guifg': '#e6e1c4'},
    \{'ctermfg': 59,  'guifg': '#6b4e32'}]

Check the User-Contributed Themes Wiki Page for more ;D


Customization

It doesn't need to look like a rainbow, you can go crazy on how you want to have it colored.

Note: The only limitation at the moment is that you can't repeat colors; Every entry on g:rainbow_levels should be unique.

Shades of Blue

let g:rainbow_levels = [
    \{'ctermfg': 51, 'guifg': '#00ffff'},
    \{'ctermfg': 45, 'guifg': '#00d7ff'},
    \{'ctermfg': 39, 'guifg': '#00afff'},
    \{'ctermfg': 33, 'guifg': '#0087ff'},
    \{'ctermfg': 27, 'guifg': '#005fff'},
    \{'ctermfg': 21, 'guifg': '#0000ff'},
    \{'ctermfg': 20, 'guifg': '#0000d7'},
    \{'ctermfg': 19, 'guifg': '#0000af'},
    \{'ctermfg': 18, 'guifg': '#000087'},
    \{'ctermfg': 17, 'guifg': '#00005f'}]



Want to keep syntax highlight?

No problem! You can change just the background colors instead.

Shades of Gray (Background)

let g:rainbow_levels = [
    \{'ctermbg': 232, 'guibg': '#080808'},
    \{'ctermbg': 233, 'guibg': '#121212'},
    \{'ctermbg': 234, 'guibg': '#1c1c1c'},
    \{'ctermbg': 235, 'guibg': '#262626'},
    \{'ctermbg': 236, 'guibg': '#303030'},
    \{'ctermbg': 237, 'guibg': '#3a3a3a'},
    \{'ctermbg': 238, 'guibg': '#444444'},
    \{'ctermbg': 239, 'guibg': '#4e4e4e'},
    \{'ctermbg': 240, 'guibg': '#585858'}]



Rainbows (Background)

let g:rainbow_levels = [
    \{'ctermbg': 222, 'guibg': '#ffd787'},
    \{'ctermbg': 223, 'guibg': '#ffd7af'},
    \{'ctermbg': 230, 'guibg': '#ffffd7'},
    \{'ctermbg': 193, 'guibg': '#d7ffaf'},
    \{'ctermbg': 195, 'guibg': '#d7ffff'},
    \{'ctermbg': 189, 'guibg': '#d7d7ff'},
    \{'ctermbg': 225, 'guibg': '#ffd7ff'},
    \{'ctermbg': 224, 'guibg': '#ffd7d7'}]



Level "Alert"

let g:rainbow_levels = [
    \{'ctermbg': 'none', 'level': 0},
    \{'ctermbg': 'none', 'level': 1},
    \{'ctermbg': 'none', 'level': 2},
    \{'ctermbg': 'none', 'level': 3},
    \
    \{'ctermbg': 3,   'guibg': '#ffc66d'},
    \{'ctermbg': 9,   'guibg': '#cc7833'},
    \{'ctermbg': 1,   'guibg': '#da4939'},
    \{'ctermbg': 160, 'guibg': '#870000'}]



Special Thanks

Where to get help

Join the chat at gitter.im/thiagoaless…

License

rainbow_levels.vim is released under the MIT License.

Made with love in Berlin