commit a086d203255f03ac07001ddd26e3cc0772211ef8 Author: Buddy Sandidge Date: Sat Nov 22 17:16:26 2014 -0800 Squashed 'vim/bundle/yaml/' content from commit 20bc37c02 git-subtree-dir: vim/bundle/yaml git-subtree-split: 20bc37c02a648959362388b4933653ab3c304645 diff --git a/README b/README new file mode 100644 index 0000000..1495ce3 --- /dev/null +++ b/README @@ -0,0 +1,41 @@ +# Vim syntax files +# Language: YAML +# Author: Igor Vergeichik +# Author: Nikolai Weibull +# Sponsor: Tom Sawyer +# Sponsor: Ingy döt Net + +YAML.VIM and YAML collection sorting scripts: + +INSTALLATION: +- Put syntax/yaml.vim in vim's syntax folder (/usr/share/vim/syntax on my system) +- Add the .yaml/.yml extensions to the filetype.vim file: | + " Yaml + au BufNewFile,BufRead *.yaml,*.yml setf yaml +- If you want add a new enty to the syntax menu: + an 50.110.370 &Syntax.WXYZ.Yaml :cal SetSyn("yaml") +- Put yamlsort.rb and yamlsort.vim into ~/.vim/scripts directory. + +SORT USE: +- Type vim command: | + :source ~/.vim/scripts/yamlsort.vim +- Then: > + is mapped to sort YAML collections in direct order, + and in reversed order. + +NOTES: +- If you want change key mapping of sorting rules edit yamlsort.vim + +TODO: +- Work with short notation of collections and mappings ({}, []) +- Support sorting of multiline values + +Changelog: + 2010-02-19: + - Merge Nikolai Weibull's rendition of yaml.vim (thanks to Phill Baker). + 2002-06-09: + - Key field can contain any number of spaces before column. + - > + If any record of collection does not key field (i.e field which + value is used in sorting), it is placed to the end of collection. + diff --git a/syntax/yaml.vim b/syntax/yaml.vim new file mode 100644 index 0000000..b7ae2a8 --- /dev/null +++ b/syntax/yaml.vim @@ -0,0 +1,126 @@ +" Vim syntax file +" Language: YAML (YAML Ain't Markup Language) +" Author: Igor Vergeichik +" Author: Nikolai Weibull +" Sponsor: Tom Sawyer +" Version: 2.0 +" + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif +syntax clear + +if exists("b:current_syntax") + finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +syn keyword yamlTodo contained TODO FIXME XXX NOTE + +syn region yamlDocumentHeader start='---' end='$' contains=yamlDirective +syn match yamlDocumentEnd '\.\.\.' +syn match yamlDirective contained '%[^:]\+:.\+' + +syn region yamlComment display oneline start='\%(^\|\s\)#' end='$' + \ contains=yamlTodo,@Spell +"syn region yamlMapping start="\w+:\s*\w+" end="$" + \ contains=yamlKey,yamlValue +syn match yamlNodeProperty "!\%(![^\\^% ]\+\|[^!][^:/ ]*\)" +syn match yamlAnchor "&.\+" +syn match yamlAlias "\*.\+" +syn match yamlDelimiter "[-,:]\(\s\|\n\)" +syn match yamlBlock "[\[\]\{\}>|]" +syn match yamlOperator '[?+-]' +syn match yamlKey '\(\.\|\w\)\+\(\s\+\(\.\|\w\)\+\)*\ze\s*:\(\s\|\n\)' +syn match yamlScalar '\(\(|\|>\)\s*\n*\r*\)\@<=\(\s\+\).*\n*\r*\(\(\3\).*\n\)*' + +" Predefined data types + +" Yaml Integer type +syn match yamlInteger display "[-+]\?\(0\|[1-9][0-9,]*\)" +syn match yamlInteger display "[-+]\?0[xX][0-9a-fA-F,]\+" + +" floating point number +syn match yamlFloating display "\<\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=\>" +syn match yamlFloating display "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>" +syn match yamlFloating display "\<\d\+e[-+]\=\d\+[fl]\=\>" +syn match yamlFloating display "\(([+-]\?inf)\)\|\((NaN)\)" +" TODO: sexagecimal and fixed (20:30.15 and 1,230.15) +syn match yamlNumber display + \ '\<[+-]\=\d\+\%(\.\d\+\%([eE][+-]\=\d\+\)\=\)\=' +syn match yamlNumber display '0\o\+' +syn match yamlNumber display '0x\x\+' +syn match yamlNumber display '([+-]\=[iI]nf)' + +" Boolean +syn keyword yamlBoolean true True TRUE false False FALSE yes Yes YES no No NO on On ON off Off OFF +syn match yamlBoolean ":.*\zs\W[+-]\(\W\|$\)" + +syn match yamlConstant '\<[~yn]\>' + +" Null +syn keyword yamlNull null Null NULL nil Nil NIL +syn match yamlNull "\W[~]\(\W\|$\)" + +syn match yamlTime "\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\?Z" +syn match yamlTime "\d\d\d\d-\d\d-\d\dt\d\d:\d\d:\d\d.\d\d-\d\d:\d\d" +syn match yamlTime "\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d.\d\d\s-\d\d:\d\d" +syn match yamlTimestamp '\d\d\d\d-\%(1[0-2]\|\d\)-\%(3[0-2]\|2\d\|1\d\|\d\)\%( \%([01]\d\|2[0-3]\):[0-5]\d:[0-5]\d.\d\d [+-]\%([01]\d\|2[0-3]\):[0-5]\d\|t\%([01]\d\|2[0-3]\):[0-5]\d:[0-5]\d.\d\d[+-]\%([01]\d\|2[0-3]\):[0-5]\d\|T\%([01]\d\|2[0-3]\):[0-5]\d:[0-5]\d.\dZ\)\=' + +" Single and double quoted scalars +syn region yamlString start="'" end="'" skip="\\'" + \ contains=yamlSingleEscape +syn region yamlString start='"' end='"' skip='\\"' + \ contains=yamlEscape + +" Escaped symbols +" every charater preceeded with slash is escaped one +syn match yamlEscape "\\." +" 2,4 and 8-digit escapes +syn match yamlEscape "\\\(x\x\{2\}\|u\x\{4\}\|U\x\{8\}\)" +syn match yamlEscape contained display +\\[\\"abefnrtv^0_ NLP]+ +syn match yamlEscape contained display '\\x\x\{2}' +syn match yamlEscape contained display '\\u\x\{4}' +syn match yamlEscape contained display '\\U\x\{8}' +" TODO: how do we get 0x85, 0x2028, and 0x2029 into this? +syn match yamlEscape display '\\\%(\r\n\|[\r\n]\)' +syn match yamlSingleEscape contained display +''+ + +syn match yamlKey "\w\+\ze\s*:\(\s\|\n\)" +syn match yamlType "![^\s]\+\s\@=" + +hi link yamlKey Identifier +hi link yamlType Type +hi link yamlInteger Number +hi link yamlFloating Float +hi link yamlNumber Number +hi link yamlEscape Special +hi link yamlSingleEscape SpecialChar +hi link yamlComment Comment +hi link yamlBlock Operator +hi link yamlDelimiter Delimiter +hi link yamlString String +hi link yamlBoolean Boolean +hi link yamlNull Boolean +hi link yamlTime String +hi link yamlTodo Todo +hi link yamlDocumentHeader PreProc +hi link yamlDocumentEnd PreProc +hi link yamlDirective Keyword +hi link yamlNodeProperty Type +hi link yamlAnchor Type +hi link yamlAlias Type +hi link yamlOperator Operator +hi link yamlScalar String +hi link yamlConstant Constant +hi link yamlTimestamp Number + +let b:current_syntax = "yaml" + +let &cpo = s:cpo_save +unlet s:cpo_save diff --git a/yamlsort.rb b/yamlsort.rb new file mode 100644 index 0000000..e989887 --- /dev/null +++ b/yamlsort.rb @@ -0,0 +1,112 @@ +# This is a script for vim-ruby for sorting collections +# +# Author: Igor Vergeichik +# Sponsor: Tom Sawyer +# Copyright (c) 2002 Tom Saywer + +class YCollection + def initialize(rule) + @buffer=VIM::Buffer.current + @window=VIM::Window.current + @lnum = @window.cursor[0] + @key=@buffer[@lnum].scan(/^([^:]+[^\s])\s*:/) + # Find collection bounds + r = bounds + # If collection found - resort it + replace(r, resort((parse r), rule)) if r[1]>0 + end + + # Detect bounds of YAML collection + # Input: no + # Output: Array - range of detected collection + def bounds + lnum = @lnum + # If line begins with a dash - this is one of collection items + if @buffer[lnum]=~/\s*-/ + coll_bounds(lnum) + else + # otherwise we need to find parent item + ind = VIM::evaluate("indent(#{lnum})").to_i + while lnum>0 + if VIM::evaluate("indent(#{lnum})").to_i0 + curr_ind = VIM::evaluate("indent(#{ln})").to_i + break if curr_inda} + diff --git a/yamlsort.vim b/yamlsort.vim new file mode 100644 index 0000000..d19817f --- /dev/null +++ b/yamlsort.vim @@ -0,0 +1,19 @@ +" Vim script for vim-ruby for sorting yaml collections +" Requires: yamlsort.rb +" Author: Igor Vergeichik +" Sponsor: Tom Sawyer +" Copyright (c) 2002 Tom Saywer + +ruby load '~/.vim/scripts/yamlsort.rb' + +" Direct sort +function! YamlSort() + ruby YCollection.new lambda{|a,b| a<=>b} +endfunction +" Reverse sort +function! YamlRSort() + ruby YCollection.new lambda{|a,b| b<=>a} +endfunction + +map :call YamlSort() +map :call YamlRSort()