├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── not-issue.md ├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── README_zh.md ├── autoload ├── rainbow.vim └── rainbow_main.vim ├── doc └── rainbow.txt ├── plugin └── rainbow_main.vim └── tests ├── test.c ├── test.css ├── test.csv ├── test.go ├── test.hs ├── test.html ├── test.html.txt ├── test.js ├── test.lua ├── test.php ├── test.pl ├── test.rb ├── test.sh ├── test.special-ft ├── test.styl ├── test.tex └── test.xml /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[Bug] " 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | ### **To Reproduce** 14 | Steps to reproduce the behavior, **Please provide a minimal piece of code to produce this issue**, along with it's filename and it's filetype detected by vim (via `:set ft?`), a piece of text is better than a picture here. For example: 15 | 16 | File: `bug.js`, filetype=javascript 17 | ``` 18 | var pair = {x: 1, y: 2} 19 | ``` 20 | 21 | Steps: 22 | 1. Open file via `vim bug.js` 23 | 2. See the color of `{` and `}` around text `{x: 1, y: 2}` 24 | 25 | ### **Expected behavior** 26 | A clear and concise description of what you expected to happen. 27 | 28 | ### **Screenshots** 29 | Provide a screenshot to describe what you got. 30 | 31 | ### **Additional context** 32 | **Are you using some third-party syntax plugins?** Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: feature request 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/not-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Not Issue 3 | about: Start a conversation which is not about bug report or feature request 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | This is not an Issue. You can type anything here except bug report and feature request. 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Rainbow Parentheses Improved 2 | Copyright 2013 LuoChen (luochen1990@gmail.com). Licensed under the Apache License 2.0. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rainbow Parentheses Improved 2 | === 3 | > help you read complex code by showing diff level of parentheses in diff color !! 4 | 5 | Description [(这里有中文版)](https://github.com/luochen1990/rainbow/blob/master/README_zh.md) 6 | --------------------------------------------------------------------------------------------------- 7 | 8 | As everyone knows, the most complex codes were composed of a mass of different kinds of parentheses (typically: lisp). 9 | This plugin will help you read these codes by showing different levels of parentheses in different colors. 10 | You can also find this plugin in **[www.vim.org](http://www.vim.org/scripts/script.php?script_id=4176)**. 11 | 12 | #### lisp 13 | ![lisp](https://raw.githubusercontent.com/luochen1990/rainbow/demo/lisp.png) 14 | #### html 15 | ![html](https://raw.githubusercontent.com/luochen1990/rainbow/demo/html.png) 16 | #### [more](https://github.com/luochen1990/rainbow/blob/demo/more.md) 17 | 18 | ### What is improved ? 19 | 20 | - no limit of parentheses levels. 21 | - separately edit guifgs and ctermfgs (the colors used for highlighting). 22 | - now you can design your own parentheses such as 'begin' and 'end'. 23 | - you can also configure anything separately for different types of files. 24 | - now you can even decide to let some operators (like + - * / , ==) highlighted with the parentheses together. 25 | - dot separated combined filetype support (`:h ft`). 26 | - json style configuration used, more understandable and readable, easier for advanced configuration. 27 | - the code is shorter and easier to read now. 28 | - smoother and faster. 29 | - the Chinese document is added. 30 | 31 | ### Referenced: 32 | - http://www.vim.org/scripts/script.php?script_id=1561 (Martin Krischik) 33 | - http://www.vim.org/scripts/script.php?script_id=3772 (kien) 34 | 35 | Install 36 | ------- 37 | 38 | #### install via Plug: 39 | 40 | ```vim 41 | Plug 'luochen1990/rainbow' 42 | let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle 43 | ``` 44 | 45 | #### install manually: 46 | 47 | - first, execute the following commands (for windows users, use `~/vimfiles` instead of `~/.vim`) 48 | 49 | ```sh 50 | git clone https://github.com/luochen1990/rainbow.git 51 | cd rainbow 52 | mkdir -p ~/.vim/plugin ~/.vim/autoload 53 | cp plugin/* ~/.vim/plugin 54 | cp autoload/* ~/.vim/autoload 55 | ``` 56 | 57 | - second, add the follow sentences to your `.vimrc` or `_vimrc` : 58 | 59 | ```vim 60 | let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle 61 | ``` 62 | 63 | - third, restart your vim and enjoy coding. 64 | 65 | Configure 66 | --------- 67 | 68 | There is an example for advanced configuration, add it to your vimrc and edit it as you wish (just keep the format). 69 | 70 | Note: you can remove these lines safely since they are all included by the [source code](https://github.com/luochen1990/rainbow/blob/master/autoload/rainbow_main.vim)). 71 | 72 | ```vim 73 | let g:rainbow_conf = { 74 | \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'], 75 | \ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'], 76 | \ 'guis': [''], 77 | \ 'cterms': [''], 78 | \ 'operators': '_,_', 79 | \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'], 80 | \ 'separately': { 81 | \ '*': {}, 82 | \ 'markdown': { 83 | \ 'parentheses_options': 'containedin=markdownCode contained', "enable rainbow for code blocks only 84 | \ }, 85 | \ 'lisp': { 86 | \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'], "lisp needs more colors for parentheses :) 87 | \ }, 88 | \ 'haskell': { 89 | \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/\v\{\ze[^-]/ end=/}/ fold'], "the haskell lang pragmas should be excluded 90 | \ }, 91 | \ 'vim': { 92 | \ 'parentheses_options': 'containedin=vimFuncBody', "enable rainbow inside vim function body 93 | \ }, 94 | \ 'perl': { 95 | \ 'syn_name_prefix': 'perlBlockFoldRainbow', "solve the [perl indent-depending-on-syntax problem](https://github.com/luochen1990/rainbow/issues/20) 96 | \ }, 97 | \ 'stylus': { 98 | \ 'parentheses': ['start=/{/ end=/}/ fold contains=@colorableGroup'], "[vim css color](https://github.com/ap/vim-css-color) compatibility 99 | \ }, 100 | \ 'css': 0, "disable this plugin for css files 101 | \ 'nerdtree': 0, "rainbow is conflicting with NERDTree, creating extra parentheses 102 | \ } 103 | \} 104 | ``` 105 | 106 | - 'guifgs': a list of `guifg` (`:h highlight-guifg`), i.e. colors for gui interface, will be used in order 107 | - 'guis': a list of `gui` (`:h highlight-gui`), will be used in order 108 | - 'ctermfgs': a list of `ctermfg` (`:h highlight-ctermfg`) 109 | - 'cterms': a list of `cterm` (`:h highlight-cterm`) 110 | - 'operators': describe the operators you want to highlight (note: be careful about special characters which needs escaping, you can find more examples [here](https://github.com/luochen1990/rainbow/issues/3), and you can also read the [vim help about syn-pattern](http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern)). note that this option will be overwritten by the `step` part of `parentheses`. 111 | - 'parentheses': a list of parentheses definitions, a parentheses definition contains parts like `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. 112 | - 'parentheses_options': parentheses options shared between different parentheses, things like `containedin=xxxFuncBody`, `contains=@Spell` (or 'contains=@NoSpell') often appears here. this option is often used to solve [3rd-party-plugin-compatibility]() problems. 113 | - 'separately': configure for specific filetypes (decided by &ft), key `*` 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). 114 | - 'syn_name_prefix': add a prefix to name of the syntax definition, this option is often used to solve [3rd-party-plugin-compatibility]() problems. 115 | - 'after': execute some vim commands after the rainbow syntax rules is defined. it is often used like `['syn clear xxx']` to solve [3rd-party-plugin-compatibility]() problems. 116 | - keep a field empty to use the default setting. 117 | 118 | To get more advanced config examples, try to search throught this [tag](https://github.com/luochen1990/rainbow/issues?utf8=%E2%9C%93&q=label%3A%22config+reference%22+). 119 | 120 | User Command 121 | ------------ 122 | 123 | - **:RainbowToggle** --you can use it to toggle this plugin. 124 | 125 | 3rd Party Plugin Compatibility 126 | ------------------------------ 127 | 128 | 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: 129 | 130 | ``` 131 | ---------------------------------------------------- 132 | | cpp | java | python | 133 | | | | | 134 | | syn cppKeyword | syn javaKeyword | syn pyKeyword | 135 | | syn cppFunc | syn javaFunc | syn pyLambda | 136 | | syn cppParen | syn javaParen | syn pyParen | 137 | | ... | ... | ... | 138 | ---------------------------------------------------- 139 | ``` 140 | 141 | But this plugin provide syntax definitions horizontally, i.e. parentheses syntax for all filetypes: 142 | 143 | ``` 144 | ---------------------------------------------------- 145 | | cpp | java | python | 146 | | | | | 147 | | syn cppKeyword | syn javaKeyword | syn pyKeyword | 148 | | syn cppFunc | syn javaFunc | syn pyLambda | 149 | | ... | ... | ... | 150 | ---------------------------------------------------- 151 | | rainbow | 152 | | | 153 | | syn cppRainbow syn javaRainbow syn pyRainbow | 154 | ---------------------------------------------------- 155 | ``` 156 | 157 | 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. 158 | 159 | 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. 160 | 161 | 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. 162 | 163 | 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](https://github.com/luochen1990/rainbow/issues?utf8=%E2%9C%93&q=label%3A%22confliction+with+other+third-party+syntax+plugins%22+) to find whether there is somebody else had the same problem and solved it. Second, you can read the following content about troubleshooting. 164 | 165 | Troubleshooting 166 | --------------- 167 | 168 | - rainbow doesn't work at all: find out the current parentheses syntax name, and use the `after` mechanism to clear these syntax. 169 | - rainbow doesn't work inside some structure: find out the syntax region name, and use the `parentheses_options` mechanism like `'containedin=xxx'`. 170 | - spell checking doesn't work inside parentheses: use the `parentheses_options` mechanism like `'contains=@Spell'`. 171 | - spell checking works inside parentheses but you don't want it: use the `parentheses_options` mechanism like `'contains=@NoSpell'`. 172 | - indent not works correctly: check the indent script you are using and search `synID` inside it to find which syntax name prefix it depends on, and use the `syn_name_prefix` mechanism to solve it. 173 | 174 | The following keymappings will help you to check the syntax name and definitions under the cursor, add them to your vimrc and restart vim: 175 | 176 | ```vim 177 | nnoremap :echo synIDattr(synID(line('.'), col('.'), 0), 'name') 178 | nnoremap :echo ("hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' 179 | \ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" 180 | \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">") 181 | nnoremap :echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') 182 | nnoremap :exec 'syn list '.synIDattr(synID(line('.'), col('.'), 0), 'name') 183 | ``` 184 | 185 | Move your cursor to a parentheses and press the keys to use them. 186 | 187 | ------------------------------------------------------------------ 188 | **Rate this script if you like it, and I'll appreciate it and improve this plugin for you because of your support! 189 | 190 | Just go to [this page](http://www.vim.org/scripts/script.php?script_id=4176) and choose `Life Changing` and click `rate`** 191 | -------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 | 彩虹括号增强版 (Rainbow Parentheses Improved) 2 | ============================================= 3 | > 通过将不同层次的括号高亮为不同的颜色, 帮助你阅读世界上最复杂的代码 4 | 5 | 插件简介: 6 | --------- 7 | 8 | 众所周知,最复杂的代码都是由一堆乱七八糟的括号组成。这款插件通过以不同的颜色展示不同层次的括号,致力于帮助你阅读这样的复杂代码。 你同样可以在[Vim官网](http://www.vim.org/scripts/script.php?script_id=4176)里看到这款插件 9 | 10 | #### lisp 11 | ![lisp](https://raw.githubusercontent.com/luochen1990/rainbow/demo/lisp.png) 12 | #### html 13 | ![html](https://raw.githubusercontent.com/luochen1990/rainbow/demo/html.png) 14 | #### [more](https://github.com/luochen1990/rainbow/blob/demo/more.md) 15 | 16 | ### 有哪些改进? 17 | 18 | - 更快速和流畅的体验。 19 | - 简短,高质量,并且易读的源代码。 20 | - 现在的版本将不再限制括号的嵌套层数。 21 | - 现在你可以分别自定义图形界面下和终端上所使用的各种括号颜色。 22 | - 现在你可以自定义括号的形式,不过在这之前你最好了解vim脚本的正则表达式。 23 | - 现在你甚至可以为不同类型的文件设定不同的配置。 24 | - 现在你甚至可以决定是否让某些符号跟着它们所在的括号一起高亮,你也可以对不同类型的文件分别设置。 25 | - 支持点分隔的复合文件类型 (`:h ft`) 26 | - 现在采用json风格的配置文件,更加可读,更易于进行高级配置。 27 | - 最后但并非不重要的一点是,如你所见,现在增加了中文说明。 28 | 29 | ### 以下是本插件所参考的旧版本: 30 | - http://www.vim.org/scripts/script.php?script_id=1561 (Martin Krischik) 31 | - http://www.vim.org/scripts/script.php?script_id=3772 (kien) 32 | 33 | 安装说明: 34 | --------- 35 | 36 | ### 使用Vundle安装: 37 | 38 | ```vim 39 | Bundle 'luochen1990/rainbow' 40 | let g:rainbow_active = 1 "0 if you want to enable it later via :RainbowToggle 41 | ``` 42 | 43 | ### 手动安装: 44 | 45 | - 首先,执行以下命令 (Windows用户需要使用 `~/vimfiles` 替代 `~/.vim`) 。 46 | 47 | ```sh 48 | git clone https://github.com/luochen1990/rainbow.git 49 | cd rainbow 50 | cp plugin/* ~/.vim/plugin 51 | cp autoload/* ~/.vim/autoload 52 | ``` 53 | 54 | - 然后,将以下句子,加入到你的vim配置文件中(windows下配置文件是`_vimrc`,而linux下是`.vimrc`) 55 | 56 | ```vim 57 | let g:rainbow_active = 1 "0 if you want to enable it later via :RainbowToggle 58 | ``` 59 | 60 | - 最后,重新启动你的vim,你就可以享受coding了。 61 | 62 | 高级配置: 63 | --------- 64 | 65 | 以下是一个配置的样例(也是我在用的配置),将它加入到你的vimrc并按照你喜欢的方式修改它(但是保持格式)你就可以精确地控制插件的行为了。 66 | 67 | ```vim 68 | let g:rainbow_conf = { 69 | \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'], 70 | \ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'], 71 | \ 'operators': '_,_', 72 | \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'], 73 | \ 'separately': { 74 | \ '*': {}, 75 | \ 'tex': { 76 | \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'], 77 | \ }, 78 | \ 'lisp': { 79 | \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'], 80 | \ }, 81 | \ 'vim': { 82 | \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'], 83 | \ }, 84 | \ 'html': { 85 | \ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=## fold'], 86 | \ }, 87 | \ 'css': 0, 88 | \ 'nerdtree': 0, "NERDTree與Rainbow會衝突,產生多餘的括號 89 | \ } 90 | \} 91 | ``` 92 | 93 | - 'guifgs': 一个`guifg`的列表 (`:h highlight-guifg`), 即GUI界面的括号颜色, 将按顺序循环使用 94 | - 'guis': 一个`gui`的列表 (`:h highlight-gui`), 将按顺序循环使用 95 | - 'ctermfgs': 一个`ctermfg`的列表 (`:h highlight-ctermfg`), 即终端下的括号颜色 96 | - 'cterms': 一个`cterm`的列表 (`:h highlight-cterm`) 97 | - 'operators': 描述你希望哪些运算符跟着与它同级的括号一起高亮(注意:留意需要转义的特殊字符,更多样例见[这里](https://github.com/luochen1990/rainbow/issues/3), 你也可以读[vim帮助 :syn-pattern](http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern)) 98 | - 'parentheses': 一个关于括号定义的列表, 每一个括号的定义包含形如以下的部分: `start=/(/`, `step=/,/`, `stop=/)/`, `fold`, `contained`, `containedin=someSynNames`, `contains=@Spell`. 各个部分具体含义可参考 `:h syntax`, 其中 `step` 为本插件的扩展定义, 表示括号中间需要高亮的运算符. 99 | - 'separately': 针对文件类型(由&ft决定)作不同的配置,未被单独设置的文件类型使用`*`下的配置,值为`0`表示仅对该类型禁用插件,值为`"default"`表示使用针对该类型的默认兼容配置 (注意, 默认兼容配置可能随着该插件版本的更新而改变, 如果你不希望它改变, 那么你应该将它拷贝一份放到你的vimrc文件里). 100 | - 省略某个字段以使用默认设置 101 | 102 | ------------------------------------------------------------------- 103 | **最后,如果你喜欢这个插件,给它一个评价,我会心存感激,并且因为你的肯定继续改进这个插件!(从[该页面](http://www.vim.org/scripts/script.php?script_id=4176)下方,选择`Life Changing`选项,然后点击`rate`)** 104 | 105 | -------------------------------------------------------------------------------- /autoload/rainbow.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2013 LuoChen (luochen1990@gmail.com). Licensed under the Apache License 2.0. 2 | 3 | if exists('s:loaded') | finish | endif | let s:loaded = 1 4 | 5 | fun s:trim(s) 6 | return substitute(a:s, '\v^\s*(.{-})\s*$', '\1', '') 7 | endfun 8 | 9 | fun s:concat(strs) 10 | return join(filter(a:strs, "v:val !~ '^[ ]*$'"), ',') 11 | endfun 12 | 13 | fun s:resolve_parenthesis_with(init_state, p) 14 | let [paren, contained, containedin, contains_prefix, contains, op] = a:init_state 15 | let p = (type(a:p) == type([])) ? ((len(a:p) == 3) ? printf('start=#%s# step=%s end=#%s#', a:p[0], op, a:p[-1]) : printf('start=#%s# end=#%s#', a:p[0], a:p[-1])) : a:p "NOTE: preprocess the old style parentheses config 16 | 17 | let ls = split(p, '\v%(%(start|step|end)\=(.)%(\1@!.)*\1[^ ]*|\w+%(\=[^ ]*)?) ?\zs', 0) 18 | for s in ls 19 | let [k, v] = [matchstr(s, '^[^=]\+\ze\(=\|$\)'), matchstr(s, '^[^=]\+=\zs.*')] 20 | if k == 'step' 21 | let op = s:trim(v) 22 | elseif k == 'contains_prefix' 23 | let contains_prefix = s:trim(v) 24 | elseif k == 'contains' 25 | let contains = s:concat([contains, s:trim(v)]) 26 | elseif k == 'containedin' 27 | let containedin = s:concat([containedin, s:trim(v)]) 28 | elseif k == 'contained' 29 | let contained = 1 30 | else 31 | let paren .= s 32 | endif 33 | endfor 34 | let rst = [paren, contained, containedin, contains_prefix, contains, op] 35 | "echom json_encode(rst) 36 | return rst 37 | endfun 38 | 39 | fun s:resolve_parenthesis_from_config(config) 40 | return s:resolve_parenthesis_with(['', 0, '', a:config.contains_prefix, '', a:config.operators], a:config.parentheses_options) 41 | endfun 42 | 43 | fun s:synID(prefix, group, lv, id) 44 | return a:prefix.'_lv'.a:lv.'_'.a:group.a:id 45 | endfun 46 | 47 | fun s:synGroupID(prefix, group, lv) 48 | return a:prefix.a:group.'_lv'.a:lv 49 | endfun 50 | 51 | fun rainbow#syn(config) 52 | let conf = a:config 53 | let prefix = conf.syn_name_prefix 54 | let cycle = conf.cycle 55 | 56 | let glob_paran_opts = s:resolve_parenthesis_from_config(conf) 57 | let b:rainbow_loaded = cycle 58 | for id in range(len(conf.parentheses)) 59 | let [paren, contained, containedin, contains_prefix, contains, op] = s:resolve_parenthesis_with(glob_paran_opts, conf.parentheses[id]) 60 | for lv in range(cycle) 61 | let lv2 = ((lv + cycle - 1) % cycle) 62 | let [rid, pid, gid2] = [s:synID(prefix, 'r', lv, id), s:synID(prefix, 'p', lv, id), s:synGroupID(prefix, 'Regions', lv2)] 63 | 64 | if len(op) > 2 65 | exe 'syn match '.s:synID(prefix, 'o', lv, id).' '.op.' containedin='.s:synID(prefix, 'r', lv, id).' contained' 66 | endif 67 | 68 | let real_contained = (lv == 0)? (contained? 'contained ' : '') : 'contained ' 69 | let real_containedin = (lv == 0)? s:concat([containedin, '@'.gid2]) : '@'.gid2 70 | let real_contains = s:concat([contains_prefix, contains]) 71 | exe 'syn region '.rid.' matchgroup='.pid.' '.real_contained.'containedin='.real_containedin.' contains='.real_contains.' '.paren 72 | endfor 73 | endfor 74 | for lv in range(cycle) 75 | exe 'syn cluster '.s:synGroupID(prefix, 'Regions', lv).' contains='.join(map(range(len(conf.parentheses)), 's:synID(prefix, "r", lv, v:val)'), ',') 76 | exe 'syn cluster '.s:synGroupID(prefix, 'Parentheses', lv).' contains='.join(map(range(len(conf.parentheses)), 's:synID(prefix, "p", lv, v:val)'), ',') 77 | exe 'syn cluster '.s:synGroupID(prefix, 'Operators', lv).' contains='.join(map(range(len(conf.parentheses)), 's:synID(prefix, "o", lv, v:val)'), ',') 78 | endfor 79 | exe 'syn cluster '.prefix.'Regions contains='.join(map(range(cycle), '"@".s:synGroupID(prefix, "Regions", v:val)'), ',') 80 | exe 'syn cluster '.prefix.'Parentheses contains='.join(map(range(cycle), '"@".s:synGroupID(prefix, "Parentheses", v:val)'), ',') 81 | exe 'syn cluster '.prefix.'Operators contains='.join(map(range(cycle), '"@".s:synGroupID(prefix, "Operators", v:val)'), ',') 82 | if has_key(conf, 'after') | for cmd in conf.after | exe cmd | endfor | endif 83 | endfun 84 | 85 | fun rainbow#syn_clear(config) 86 | let conf = a:config 87 | let prefix = conf.syn_name_prefix 88 | 89 | for id in range(len(conf.parentheses)) 90 | for lv in range(conf.cycle) 91 | let [rid, oid] = [s:synID(prefix, 'r', lv, id), s:synID(prefix, 'o', lv, id)] 92 | exe 'syn clear '.rid 93 | exe 'syn clear '.oid 94 | endfor 95 | endfor 96 | endfun 97 | 98 | fun rainbow#hi(config) 99 | let conf = a:config 100 | let prefix = conf.syn_name_prefix 101 | 102 | for id in range(len(conf.parentheses)) 103 | for lv in range(conf.cycle) 104 | let [pid, oid] = [s:synID(prefix, 'p', lv, id), s:synID(prefix, 'o', lv, id)] 105 | let ctermfg = conf.ctermfgs[lv % len(conf.ctermfgs)] 106 | let guifg = conf.guifgs[lv % len(conf.guifgs)] 107 | let cterm = conf.cterms[lv % len(conf.cterms)] 108 | let gui = conf.guis[lv % len(conf.guis)] 109 | let hi_style = 'ctermfg='.ctermfg.' guifg='.guifg.(len(cterm) > 0 ? ' cterm='.cterm : '').(len(gui) > 0 ? ' gui='.gui : '') 110 | exe 'hi '.pid.' '.hi_style 111 | exe 'hi '.oid.' '.hi_style 112 | endfor 113 | endfor 114 | endfun 115 | 116 | fun rainbow#hi_clear(config) 117 | let conf = a:config 118 | let prefix = conf.syn_name_prefix 119 | 120 | for id in range(len(conf.parentheses)) 121 | for lv in range(conf.cycle) 122 | let [pid, oid] = [s:synID(prefix, 'p', lv, id), s:synID(prefix, 'o', lv, id)] 123 | exe 'hi clear '.pid 124 | exe 'hi clear '.oid 125 | endfor 126 | endfor 127 | endfun 128 | 129 | -------------------------------------------------------------------------------- /autoload/rainbow_main.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2013 LuoChen (luochen1990@gmail.com). Licensed under the Apache License 2.0. 2 | 3 | let s:rainbow_conf = { 4 | \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'], 5 | \ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'], 6 | \ 'guis': [''], 7 | \ 'cterms': [''], 8 | \ 'operators': '_,_', 9 | \ 'contains_prefix': 'TOP', 10 | \ 'parentheses_options': '', 11 | \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'], 12 | \ 'separately': { 13 | \ '*': {}, 14 | \ 'markdown': { 15 | \ 'parentheses_options': 'containedin=markdownCode contained', 16 | \ }, 17 | \ 'lisp': { 18 | \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'], 19 | \ }, 20 | \ 'haskell': { 21 | \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/\v\{\ze[^-]/ end=/}/ fold'], 22 | \ }, 23 | \ 'ocaml': { 24 | \ 'parentheses': ['start=/(\ze[^*]/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/\[|/ end=/|\]/ fold', 'start=/{/ end=/}/ fold'], 25 | \ }, 26 | \ 'tex': { 27 | \ 'parentheses_options': 'containedin=texDocZone', 28 | \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'], 29 | \ }, 30 | \ 'vim': { 31 | \ 'parentheses_options': 'containedin=vimFuncBody,vimExecute', 32 | \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold'], 33 | \ }, 34 | \ 'xml': { 35 | \ 'syn_name_prefix': 'xmlRainbow', 36 | \ 'parentheses': ['start=/\v\<\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'))?)*\>/ end=## fold'], 37 | \ }, 38 | \ 'xhtml': { 39 | \ 'parentheses': ['start=/\v\<\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'))?)*\>/ end=## fold'], 40 | \ }, 41 | \ 'html': { 42 | \ 'parentheses': ['start=/\v\<((script|style|area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*(\n|\s)*\>/ end=## fold'], 43 | \ }, 44 | \ 'lua': { 45 | \ 'parentheses': ["start=/(/ end=/)/", "start=/{/ end=/}/", "start=/\\v\\[\\ze($|[^[])/ end=/\\]/"], 46 | \ }, 47 | \ 'perl': { 48 | \ 'syn_name_prefix': 'perlBlockFoldRainbow', 49 | \ }, 50 | \ 'php': { 51 | \ 'syn_name_prefix': 'phpBlockRainbow', 52 | \ 'contains_prefix': '', 53 | \ 'parentheses': ['start=/(/ end=/)/ containedin=@htmlPreproc contains=@phpClTop', 'start=/\[/ end=/\]/ containedin=@htmlPreproc contains=@phpClTop', 'start=/{/ end=/}/ containedin=@htmlPreproc contains=@phpClTop', 'start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=## fold contains_prefix=TOP'], 54 | \ }, 55 | \ 'stylus': { 56 | \ 'parentheses': ['start=/{/ end=/}/ fold contains=@colorableGroup'], 57 | \ }, 58 | \ 'css': 0, 59 | \ 'sh': 0, 60 | \ 'vimwiki': 0, 61 | \ } 62 | \} 63 | 64 | fun s:eq(x, y) 65 | return type(a:x) == type(a:y) && a:x == a:y 66 | endfun 67 | 68 | fun s:gcd(a, b) 69 | let [a, b, t] = [a:a, a:b, 0] 70 | while b != 0 71 | let t = b 72 | let b = a % b 73 | let a = t 74 | endwhile 75 | return a 76 | endfun 77 | 78 | fun s:lcm(a, b) 79 | return (a:a / s:gcd(a:a, a:b)) * a:b 80 | endfun 81 | 82 | fun rainbow_main#gen_config(ft) 83 | let g = exists('g:rainbow_conf')? g:rainbow_conf : {} 84 | "echom 'g:rainbow_conf:' string(g) 85 | let s = get(g, 'separately', {}) 86 | "echom 'g:rainbow_conf.separately:' string(s) 87 | let dft_conf = extend(copy(s:rainbow_conf), g) | unlet dft_conf.separately 88 | "echom 'default config options:' string(dft_conf) 89 | let dx_conf = s:rainbow_conf.separately['*'] 90 | "echom 'default star config:' string(dx_conf) 91 | let ds_conf = get(s:rainbow_conf.separately, a:ft, dx_conf) 92 | "echom 'default separately config:' string(ds_conf) 93 | let ux_conf = get(s, '*', ds_conf) 94 | "echom 'user star config:' string(ux_conf) 95 | let us_conf = get(s, a:ft, ux_conf) 96 | "echom 'user separately config:' string(us_conf) 97 | let af_conf = (s:eq(us_conf, 'default') ? ds_conf : us_conf) 98 | "echom 'almost finally config:' string(af_conf) 99 | if s:eq(af_conf, 0) 100 | return 0 101 | else 102 | let conf = extend(extend({'syn_name_prefix': substitute(a:ft, '\v\A+(\a)', '\u\1', 'g').'Rainbow'}, dft_conf), af_conf) 103 | let conf.cycle = (has('gui_running') || (has('termguicolors') && &termguicolors)) ? s:lcm(len(conf.guifgs), len(conf.guis)) : s:lcm(len(conf.ctermfgs), len(conf.cterms)) 104 | return conf 105 | endif 106 | endfun 107 | 108 | fun rainbow_main#gen_configs(ft) 109 | return filter(map(split(a:ft, '\v\.'), 'rainbow_main#gen_config(v:val)'), 'type(v:val) == type({})') 110 | endfun 111 | 112 | fun rainbow_main#load() 113 | let b:rainbow_confs = rainbow_main#gen_configs(&filetype) 114 | for conf in b:rainbow_confs 115 | call rainbow#syn(conf) 116 | call rainbow#hi(conf) 117 | endfor 118 | endfun 119 | 120 | fun rainbow_main#clear() 121 | if !exists('b:rainbow_confs') | return | endif 122 | for conf in b:rainbow_confs 123 | call rainbow#hi_clear(conf) 124 | call rainbow#syn_clear(conf) 125 | endfor 126 | unlet b:rainbow_confs 127 | endfun 128 | 129 | fun rainbow_main#toggle() 130 | if exists('b:rainbow_confs') 131 | call rainbow_main#clear() 132 | else 133 | call rainbow_main#load() 134 | endif 135 | endfun 136 | 137 | -------------------------------------------------------------------------------- /doc/rainbow.txt: -------------------------------------------------------------------------------- 1 | Rainbow Parentheses Improved *rainbow* 2 | ========================================================================== 3 | 4 | Commands: *rainbow-commands* 5 | -------------------------------------------------------------------------- 6 | 7 | *RainbowToggle* --- toggle this plugin on/off 8 | *RainbowToggleOn* --- toggle this plugin on 9 | *RainbowToggleOff* --- toggle this plugin off 10 | 11 | Configurations: *rainbow-config* 12 | -------------------------------------------------------------------------- 13 | 14 | *g:rainbow_active* --- 1 to auto enable this plugin 15 | 0 to enable it later via :RainbowToggle 16 | *g:rainbow_conf* --- https://github.com/luochen1990/rainbow#configure 17 | 18 | vim:tw=78:ts=8:ft=help:norl: 19 | -------------------------------------------------------------------------------- /plugin/rainbow_main.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2013 LuoChen (luochen1990@gmail.com). Licensed under the Apache License 2.0. 2 | 3 | if exists('s:loaded') || !(exists('g:rainbow_active') || exists('g:rainbow_conf')) | finish | endif | let s:loaded = 1 4 | 5 | command! RainbowToggle call rainbow_main#toggle() 6 | command! RainbowToggleOn call rainbow_main#load() 7 | command! RainbowToggleOff call rainbow_main#clear() 8 | 9 | if (exists('g:rainbow_active') && g:rainbow_active) 10 | auto syntax * call rainbow_main#load() 11 | auto colorscheme * call rainbow_main#load() 12 | endif 13 | -------------------------------------------------------------------------------- /tests/test.c: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | typoo 6 | (typoo) 7 | 8 | int main() { 9 | printf("hello, world"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/test.css: -------------------------------------------------------------------------------- 1 | div { 2 | color: red 3 | } 4 | -------------------------------------------------------------------------------- /tests/test.csv: -------------------------------------------------------------------------------- 1 | a,b,c,d 2 | 1,2,3,4 3 | 1,,3,4 4 | 1,,,4 5 | 1 , , , 4 6 | 1,2,3,4,5 7 | 1, 2, 3, 4 8 | 1 ,2 ,3, 4, 5 9 | 1 , 2 , 3 , 4 10 | 1 , 2 , 3 , 4 11 | 1, 3 12 | 1,2,3 13 | 1,3,4,5 14 | 15 | -------------------------------------------------------------------------------- /tests/test.go: -------------------------------------------------------------------------------- 1 | typoo 2 | (typoo) 3 | 4 | client := &http.Client{} 5 | -------------------------------------------------------------------------------- /tests/test.hs: -------------------------------------------------------------------------------- 1 | {- this is a comment block -} 2 | 3 | xs = [1, 2, 3] 4 | ps = [(1, 2), (3, 1 / 4)] 5 | 6 | -------------------------------------------------------------------------------- /tests/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 |
11 | 12 | (1 + (2 + 3)) 13 |
14 | 15 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/test.html.txt: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | (1 + (2 + 3)) 5 |
6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/test.js: -------------------------------------------------------------------------------- 1 | typoo 2 | (typoo) 3 | 4 | console.log({w: 200, h: 100, pos: [{x: 1, y: 2}, {x: 3, y: 4}]}) 5 | 6 | -------------------------------------------------------------------------------- /tests/test.lua: -------------------------------------------------------------------------------- 1 | (function(args) 2 | lst = { a=function(arg) print("hello") end, 3 | b=(1+2)*3/4, 4 | [3+5]={ ["hello"]=("hi") }, 5 | } 6 | lst[ 7 | (function() return 0 end)()] = 1 8 | end)("blah") 9 | 10 | [[ 11 | Special lua string... 12 | ]] 13 | -------------------------------------------------------------------------------- /tests/test.php: -------------------------------------------------------------------------------- 1 | 0) 3 | { 4 | echo "Error: " . $_FILES["file"]["error"] . "
"; 5 | } 6 | else 7 | { 8 | echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; 9 | } 10 | ?> 11 | 12 | hello (world) 13 | 14 | -------------------------------------------------------------------------------- /tests/test.pl: -------------------------------------------------------------------------------- 1 | typoo 2 | (typoo) 3 | 4 | sub test { 5 | correct indent; 6 | } 7 | 8 | if ($test) { 9 | incorrect indent; 10 | } 11 | -------------------------------------------------------------------------------- /tests/test.rb: -------------------------------------------------------------------------------- 1 | {{{}}} 2 | ((())) 3 | [[[]]] 4 | [[[[]]]] 5 | 6 | def sample_function(a, b) 7 | ((())) 8 | [[[]]] 9 | end 10 | 11 | class SampleClass 12 | def sample_method(a, b) 13 | [[[]]] 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /tests/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | typoo 3 | (typoo) 4 | 5 | if stuff 6 | then 7 | somestuff 8 | test = (()) 9 | (()) 10 | a = (1 + (2 + 3)) 11 | if 12 | then 13 | elif 14 | then 15 | else 16 | fi 17 | else 18 | otherstuff 19 | fi 20 | 21 | if stuff 22 | then 23 | somestuff 24 | else 25 | otherstuff 26 | fi 27 | 28 | function f() { 29 | if 30 | fi 31 | } 32 | 33 | 34 | # check if command exists 35 | command_exists () { 36 | type "${1}" > /dev/null 2>&1; 37 | a = (1 + (2 + 3)) 38 | } 39 | 40 | # Fetch the update 41 | fetch() { 42 | if type wget > /dev/null 2>&1 ; then 43 | $debug && echo "fetching update via wget" 44 | wget --no-check-certificate -O "${2}" "${1}" >/dev/null 2>&1 45 | elif type curl > /dev/null 2>&1 ; then 46 | $debug && echo "fetching update via curl" 47 | curl --insecure --remote-name -o "${2}" "${1}" >/dev/null 2>&1 48 | else 49 | echo 'Warning: Neither wget nor curl is available. online updates unavailable' >&2 50 | exit 1 51 | fi 52 | } 53 | -------------------------------------------------------------------------------- /tests/test.special-ft: -------------------------------------------------------------------------------- 1 | (((()))) 2 | [[[[]]]] 3 | {{{{}}}} 4 | 5 | # vim: set ft=this-is-a--very-SPECIAL-filetype : 6 | -------------------------------------------------------------------------------- /tests/test.styl: -------------------------------------------------------------------------------- 1 | div { 2 | color: red 3 | } 4 | -------------------------------------------------------------------------------- /tests/test.tex: -------------------------------------------------------------------------------- 1 | \documentclass[]{article} 2 | 3 | {{{{}}}} 4 | ((((((())))))) 5 | [[[[[[]]]]]] 6 | \begin{document} 7 | ((((())))) 8 | ${{{{}}}}$ 9 | {{{{}}}} 10 | [[[[[[]]]]]] 11 | \end{document} 12 | -------------------------------------------------------------------------------- /tests/test.xml: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | 6 | 7 | --------------------------------------------------------------------------------