├── LICENSE ├── README.md ├── ftdetect └── toml.vim ├── ftplugin └── toml.vim ├── syntax └── toml.vim └── test └── test.toml /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Caleb Spare 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-toml 2 | 3 | Vim syntax for [TOML](https://github.com/toml-lang/toml). As of Neovim 0.6 and 4 | Vim 8.2.3519, these runtime files are included in the main (Neo)Vim 5 | distribution. 6 | 7 | ## Installation 8 | 9 | ### Vim packages (recommended; Vim 8+ only) 10 | 11 | Clone or submodule this repo into your Vim packages location. Example: 12 | 13 | ``` 14 | git clone https://github.com/cespare/vim-toml.git ~/.vim/pack/plugins/start/vim-toml 15 | ``` 16 | 17 | ### Pathogen 18 | 19 | Set up [Pathogen](https://github.com/tpope/vim-pathogen) then clone/submodule 20 | this repo into `~/.vim/bundle/toml`, or wherever you've pointed your Pathogen. 21 | 22 | ### Vundle 23 | 24 | Set up [Vundle](https://github.com/VundleVim/Vundle.vim) then add `Plugin 25 | 'cespare/vim-toml'` to your vimrc and run `:PluginInstall` from a fresh vim. 26 | 27 | ### vim-plug 28 | 29 | Set up [vim-plug](https://github.com/junegunn/vim-plug). In your .vimrc, between 30 | the lines for `call plug#begin()` and `call plug#end()`, add the line `Plug 31 | 'cespare/vim-toml', { 'branch': 'main' }`. Reload your .vimrc and then run `:PlugInstall`. 32 | 33 | ### Janus 34 | 35 | Set up [Janus](https://github.com/carlhuda/janus) and then clone/submodule this 36 | repo into `~/.janus` and restart vim. 37 | 38 | ## Contributing 39 | 40 | Contributions are very welcome! Just open a PR. 41 | -------------------------------------------------------------------------------- /ftdetect/toml.vim: -------------------------------------------------------------------------------- 1 | " Go dep and Rust use several TOML config files that are not named with .toml. 2 | autocmd BufNewFile,BufRead *.toml,pdm.lock,Gopkg.lock,Cargo.lock,*/.cargo/config,*/.cargo/credentials,Pipfile set filetype=toml 3 | -------------------------------------------------------------------------------- /ftplugin/toml.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin 2 | " Language: TOML 3 | " Homepage: https://github.com/cespare/vim-toml 4 | " Maintainer: Aman Verma 5 | " Author: Kevin Ballard 6 | " Last Change: Sep 21, 2021 7 | 8 | if exists('b:did_ftplugin') 9 | finish 10 | endif 11 | let b:did_ftplugin = 1 12 | 13 | let s:save_cpo = &cpo 14 | set cpo&vim 15 | let b:undo_ftplugin = 'setlocal commentstring< comments< iskeyword<' 16 | 17 | setlocal commentstring=#\ %s 18 | setlocal comments=:# 19 | setlocal iskeyword+=- 20 | 21 | let &cpo = s:save_cpo 22 | unlet s:save_cpo 23 | 24 | " vim: et sw=2 sts=2 25 | -------------------------------------------------------------------------------- /syntax/toml.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: TOML 3 | " Homepage: https://github.com/cespare/vim-toml 4 | " Maintainer: Aman Verma 5 | " Previous Maintainer: Caleb Spare 6 | " Last Change: Oct 8, 2021 7 | 8 | if exists('b:current_syntax') 9 | finish 10 | endif 11 | 12 | syn match tomlEscape /\\[btnfr"/\\]/ display contained 13 | syn match tomlEscape /\\u\x\{4}/ contained 14 | syn match tomlEscape /\\U\x\{8}/ contained 15 | syn match tomlLineEscape /\\$/ contained 16 | 17 | " Basic strings 18 | syn region tomlString oneline start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=tomlEscape 19 | " Multi-line basic strings 20 | syn region tomlString start=/"""/ end=/"""/ contains=tomlEscape,tomlLineEscape 21 | " Literal strings 22 | syn region tomlString oneline start=/'/ end=/'/ 23 | " Multi-line literal strings 24 | syn region tomlString start=/'''/ end=/'''/ 25 | 26 | syn match tomlInteger /[+-]\=[1-9]\(_\=\d\)*/ display 27 | syn match tomlInteger /[+-]\=0/ display 28 | syn match tomlInteger /[+-]\=0x[[:xdigit:]]\(_\=[[:xdigit:]]\)*/ display 29 | syn match tomlInteger /[+-]\=0o[0-7]\(_\=[0-7]\)*/ display 30 | syn match tomlInteger /[+-]\=0b[01]\(_\=[01]\)*/ display 31 | syn match tomlInteger /[+-]\=\(inf\|nan\)/ display 32 | 33 | syn match tomlFloat /[+-]\=\d\(_\=\d\)*\.\d\+/ display 34 | syn match tomlFloat /[+-]\=\d\(_\=\d\)*\(\.\d\(_\=\d\)*\)\=[eE][+-]\=\d\(_\=\d\)*/ display 35 | 36 | syn match tomlBoolean /\<\%(true\|false\)\>/ display 37 | 38 | " https://tools.ietf.org/html/rfc3339 39 | syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}/ display 40 | syn match tomlDate /\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?/ display 41 | syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}[T ]\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?\%(Z\|[+-]\d\{2\}:\d\{2\}\)\?/ display 42 | 43 | syn match tomlDotInKey /\v[^.]+\zs\./ contained display 44 | syn match tomlKey /\v(^|[{,])\s*\zs[[:alnum:]._-]+\ze\s*\=/ contains=tomlDotInKey display 45 | syn region tomlKeyDq oneline start=/\v(^|[{,])\s*\zs"/ end=/"\ze\s*=/ contains=tomlEscape 46 | syn region tomlKeySq oneline start=/\v(^|[{,])\s*\zs'/ end=/'\ze\s*=/ 47 | 48 | syn region tomlTable oneline start=/^\s*\[[^\[]/ end=/\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey 49 | 50 | syn region tomlTableArray oneline start=/^\s*\[\[/ end=/\]\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey 51 | 52 | syn region tomlKeyValueArray start=/=\s*\[\zs/ end=/\]/ contains=@tomlValue 53 | 54 | syn region tomlArray start=/\[/ end=/\]/ contains=@tomlValue contained 55 | 56 | syn cluster tomlValue contains=tomlArray,tomlString,tomlInteger,tomlFloat,tomlBoolean,tomlDate,tomlComment 57 | 58 | syn keyword tomlTodo TODO FIXME XXX BUG contained 59 | 60 | syn match tomlComment /#.*/ contains=@Spell,tomlTodo 61 | 62 | hi def link tomlComment Comment 63 | hi def link tomlTodo Todo 64 | hi def link tomlTableArray Title 65 | hi def link tomlTable Title 66 | hi def link tomlDotInKey Normal 67 | hi def link tomlKeySq Identifier 68 | hi def link tomlKeyDq Identifier 69 | hi def link tomlKey Identifier 70 | hi def link tomlDate Constant 71 | hi def link tomlBoolean Boolean 72 | hi def link tomlFloat Float 73 | hi def link tomlInteger Number 74 | hi def link tomlString String 75 | hi def link tomlLineEscape SpecialChar 76 | hi def link tomlEscape SpecialChar 77 | 78 | syn sync minlines=500 79 | let b:current_syntax = 'toml' 80 | 81 | " vim: et sw=2 sts=2 82 | -------------------------------------------------------------------------------- /test/test.toml: -------------------------------------------------------------------------------- 1 | # Visual test file. 2 | # You can run 3 | # 4 | # nnoremap echo synIDattr(synID(line('.'), col('.'), 1), 'name') 5 | # 6 | # and then press F10 to get the highlight group under the cursor. 7 | 8 | # https://github.com/cespare/vim-toml/issues/9 9 | issue9 = [ 10 | ["a", "b", "c"] 11 | ] 12 | 13 | # https://github.com/cespare/vim-toml/issues/10 14 | issue10_1 = -12 15 | issue10_2 = +200.3 16 | 17 | # https://github.com/cespare/vim-toml/issues/11 18 | issue11 = -210_000.0 19 | 20 | # https://github.com/cespare/vim-toml/issues/13 21 | issue13 = { version="1.0", features=["derive"] } 22 | 23 | # https://github.com/cespare/vim-toml/pull/52 24 | [foo.baz] 25 | apple.type = "fruit" 26 | 3.14159 = "pi" 27 | "127.0.0.1" = "value" 28 | 29 | [[foo.quux]] 30 | e = 2 31 | 32 | # https://github.com/cespare/vim-toml/issues/58 33 | site."google.com" = true 34 | 35 | # vim: et sw=2 sts=2 36 | --------------------------------------------------------------------------------