├── ftdetect └── gdscript.vim ├── README.md ├── LICENSE ├── indent └── gdscript.vim └── syntax └── gdscript.vim /ftdetect/gdscript.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.gd set filetype=gdscript 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | vim-gdscript 2 | ============ 3 | 4 | gdscript syntax file for vim 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 quabug 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /indent/gdscript.vim: -------------------------------------------------------------------------------- 1 | " Vim indent file 2 | " Language: Python 3 | " Maintainer: Bram Moolenaar 4 | " Original Author: David Bustos 5 | " Last Change: 2013 Jul 9 6 | 7 | " Only load this indent file when no other was loaded. 8 | if exists("b:did_indent") 9 | finish 10 | endif 11 | let b:did_indent = 1 12 | 13 | " Some preliminary settings 14 | setlocal nolisp " Make sure lisp indenting doesn't supersede us 15 | setlocal autoindent " indentexpr isn't much help otherwise 16 | setlocal noexpandtab " tab must not be converted in spaces, otherwise an error would occur in Godot 17 | 18 | setlocal indentexpr=GetPythonIndent(v:lnum) 19 | setlocal indentkeys+=<:>,=elif,=except 20 | 21 | " Only define the function once. 22 | if exists("*GetPythonIndent") 23 | finish 24 | endif 25 | let s:keepcpo= &cpo 26 | set cpo&vim 27 | 28 | " Come here when loading the script the first time. 29 | 30 | let s:maxoff = 50 " maximum number of lines to look backwards for () 31 | 32 | function GetPythonIndent(lnum) 33 | 34 | " If this line is explicitly joined: If the previous line was also joined, 35 | " line it up with that one, otherwise add two 'shiftwidth' 36 | if getline(a:lnum - 1) =~ '\\$' 37 | if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$' 38 | return indent(a:lnum - 1) 39 | endif 40 | return indent(a:lnum - 1) + (exists("g:pyindent_continue") ? eval(g:pyindent_continue) : (shiftwidth() * 2)) 41 | endif 42 | 43 | " If the start of the line is in a string don't change the indent. 44 | if has('syntax_items') 45 | \ && synIDattr(synID(a:lnum, 1, 1), "name") =~ "String$" 46 | return -1 47 | endif 48 | 49 | " Search backwards for the previous non-empty line. 50 | let plnum = prevnonblank(v:lnum - 1) 51 | 52 | if plnum == 0 53 | " This is the first non-empty line, use zero indent. 54 | return 0 55 | endif 56 | 57 | " If the previous line is inside parenthesis, use the indent of the starting 58 | " line. 59 | " Trick: use the non-existing "dummy" variable to break out of the loop when 60 | " going too far back. 61 | call cursor(plnum, 1) 62 | let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW', 63 | \ "line('.') < " . (plnum - s:maxoff) . " ? dummy :" 64 | \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" 65 | \ . " =~ '\\(Comment\\|Todo\\|String\\)$'") 66 | if parlnum > 0 67 | let plindent = indent(parlnum) 68 | let plnumstart = parlnum 69 | else 70 | let plindent = indent(plnum) 71 | let plnumstart = plnum 72 | endif 73 | 74 | 75 | " When inside parenthesis: If at the first line below the parenthesis add 76 | " two 'shiftwidth', otherwise same as previous line. 77 | " i = (a 78 | " + b 79 | " + c) 80 | call cursor(a:lnum, 1) 81 | let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW', 82 | \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" 83 | \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" 84 | \ . " =~ '\\(Comment\\|Todo\\|String\\)$'") 85 | if p > 0 86 | if p == plnum 87 | " When the start is inside parenthesis, only indent one 'shiftwidth'. 88 | let pp = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW', 89 | \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" 90 | \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" 91 | \ . " =~ '\\(Comment\\|Todo\\|String\\)$'") 92 | if pp > 0 93 | return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth()) 94 | endif 95 | return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : (shiftwidth() * 2)) 96 | endif 97 | if plnumstart == p 98 | return indent(plnum) 99 | endif 100 | return plindent 101 | endif 102 | 103 | 104 | " Get the line and remove a trailing comment. 105 | " Use syntax highlighting attributes when possible. 106 | let pline = getline(plnum) 107 | let pline_len = strlen(pline) 108 | if has('syntax_items') 109 | " If the last character in the line is a comment, do a binary search for 110 | " the start of the comment. synID() is slow, a linear search would take 111 | " too long on a long line. 112 | if synIDattr(synID(plnum, pline_len, 1), "name") =~ "\\(Comment\\|Todo\\)$" 113 | let min = 1 114 | let max = pline_len 115 | while min < max 116 | let col = (min + max) / 2 117 | if synIDattr(synID(plnum, col, 1), "name") =~ "\\(Comment\\|Todo\\)$" 118 | let max = col 119 | else 120 | let min = col + 1 121 | endif 122 | endwhile 123 | let pline = strpart(pline, 0, min - 1) 124 | endif 125 | else 126 | let col = 0 127 | while col < pline_len 128 | if pline[col] == '#' 129 | let pline = strpart(pline, 0, col) 130 | break 131 | endif 132 | let col = col + 1 133 | endwhile 134 | endif 135 | 136 | " If the previous line ended with a colon, indent this line 137 | if pline =~ ':\s*$' 138 | return plindent + shiftwidth() 139 | endif 140 | 141 | " If the previous line was a stop-execution statement... 142 | if getline(plnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>' 143 | " See if the user has already dedented 144 | if indent(a:lnum) > indent(plnum) - shiftwidth() 145 | " If not, recommend one dedent 146 | return indent(plnum) - shiftwidth() 147 | endif 148 | " Otherwise, trust the user 149 | return -1 150 | endif 151 | 152 | " If the current line begins with a keyword that lines up with "try" 153 | if getline(a:lnum) =~ '^\s*\(except\|finally\)\>' 154 | let lnum = a:lnum - 1 155 | while lnum >= 1 156 | if getline(lnum) =~ '^\s*\(try\|except\)\>' 157 | let ind = indent(lnum) 158 | if ind >= indent(a:lnum) 159 | return -1 " indent is already less than this 160 | endif 161 | return ind " line up with previous try or except 162 | endif 163 | let lnum = lnum - 1 164 | endwhile 165 | return -1 " no matching "try"! 166 | endif 167 | 168 | " If the current line begins with a header keyword, dedent 169 | if getline(a:lnum) =~ '^\s*\(elif\|else\)\>' 170 | 171 | " Unless the previous line was a one-liner 172 | if getline(plnumstart) =~ '^\s*\(for\|if\|try\)\>' 173 | return plindent 174 | endif 175 | 176 | " Or the user has already dedented 177 | if indent(a:lnum) <= plindent - shiftwidth() 178 | return -1 179 | endif 180 | 181 | return plindent - shiftwidth() 182 | endif 183 | 184 | " When after a () construct we probably want to go back to the start line. 185 | " a = (b 186 | " + c) 187 | " here 188 | if parlnum > 0 189 | return plindent 190 | endif 191 | 192 | return -1 193 | 194 | endfunction 195 | 196 | let &cpo = s:keepcpo 197 | unlet s:keepcpo 198 | 199 | " vim:sw=2 200 | -------------------------------------------------------------------------------- /syntax/gdscript.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: GDScript 3 | " Maintainer: quabug 4 | " Contributor: Hilton Medeiros 5 | " Contributor: Ludvig Böklin 6 | " Last Change: 2016 January 29 7 | 8 | if version < 600 9 | syntax clear 10 | elseif exists("b:current_syntax") 11 | finish 12 | endif 13 | 14 | " We need nocompatible mode in order to continue lines with backslashes. 15 | " Original setting will be restored. 16 | let s:cpo_save = &cpo 17 | set cpo&vim 18 | " 19 | syn keyword gdscriptStatement false null true 20 | syn keyword gdscriptStatement assert break continue tool breakpoint 21 | syn keyword gdscriptStatement pass self return 22 | syn keyword gdscriptStatement remote sync master slave nextgroup=gdscriptStatement skipwhite 23 | syn keyword gdscriptStatement class func nextgroup=gdscriptFunction skipwhite 24 | syn keyword gdscriptConditional elif else if 25 | syn keyword gdscriptRepeat for while 26 | syn keyword gdscriptOperator and in not or extends 27 | syn match gdscriptInclude "^extends" 28 | syn keyword gdscriptStorage export 29 | syn keyword gdscriptType var const int real bool String 30 | syn keyword gdscriptStructure enum 31 | 32 | syn keyword gdscriptType Vector2 Size2 Rect2 Vector3 Matrix32 Plane 33 | syn keyword gdscriptType Quat AABB Box3 Matrix3 Transform 34 | syn keyword gdscriptType Color Image NodePath RID Object InputEvent 35 | syn keyword gdscriptType RawArray IntArray FloatArray StringArray 36 | syn keyword gdscriptType Vector2Array Vector3Array ColorArray 37 | syn keyword gdscriptType Nil Dictionary Array 38 | 39 | syn keyword gdscriptBuiltin sin cos tan sinh cosh tanh asin acos atan atan2 40 | syn keyword gdscriptBuiltin sqrt fmod fposmod floor ceil round abs sign pow 41 | syn keyword gdscriptBuiltin log exp isnan isinf ease decimals stepify lerp 42 | syn keyword gdscriptBuiltin dectime randomize randi randf rand_range rand_seed 43 | syn keyword gdscriptBuiltin deg2rad rad2deg linear2db db2linear max min clamp 44 | syn keyword gdscriptBuiltin nearest_po2 weakref funcref convert str print 45 | syn keyword gdscriptBuiltin printt printerr printraw range load inst2dict 46 | syn keyword gdscriptBuiltin dict2inst preload print_stack onready 47 | 48 | syn match gdscriptDecorator "@" display nextgroup=gdscriptFunction skipwhite 49 | " The zero-length non-grouping match before the function name is 50 | " extremely important in gdscriptFunction. Without it, everything is 51 | " interpreted as a function inside the contained environment of 52 | " doctests. 53 | " A dot must be allowed because of @MyClass.myfunc decorators. 54 | syn match gdscriptFunction /\k\+\%(\s*(\)\@=/ 55 | 56 | syn match gdscriptComment "#.*$" contains=gdscriptTodo,@Spell 57 | syn keyword gdscriptTodo FIXME NOTE NOTES TODO XXX HACK contained 58 | 59 | setlocal commentstring=#%s 60 | 61 | " Triple-quoted strings can contain doctests. 62 | syn region gdscriptString 63 | \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" 64 | \ contains=gdscriptEscape,@Spell 65 | syn region gdscriptRawString 66 | \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" 67 | \ contains=@Spell 68 | 69 | syn match gdscriptEscape +\\[abfnrtv'"\\]+ contained 70 | syn match gdscriptEscape "\\\o\{1,3}" contained 71 | syn match gdscriptEscape "\\x\x\{2}" contained 72 | syn match gdscriptEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained 73 | " gdscript allows case-insensitive Unicode IDs: http://www.unicode.org/charts/ 74 | syn match gdscriptEscape "\\N{\a\+\%(\s\a\+\)*}" contained 75 | syn match gdscriptEscape "\\$" 76 | 77 | "if exists("gdscript_highlight_all") 78 | "if exists("gdscript_no_builtin_highlight") 79 | "unlet gdscript_no_builtin_highlight 80 | "endif 81 | "if exists("gdscript_no_doctest_code_highlight") 82 | "unlet gdscript_no_doctest_code_highlight 83 | "endif 84 | "if exists("gdscript_no_doctest_highlight") 85 | "unlet gdscript_no_doctest_highlight 86 | "endif 87 | "if exists("gdscript_no_exception_highlight") 88 | "unlet gdscript_no_exception_highlight 89 | "endif 90 | "if exists("gdscript_no_number_highlight") 91 | "unlet gdscript_no_number_highlight 92 | "endif 93 | "let gdscript_space_error_highlight = 1 94 | "endif 95 | "if !exists("gdscript_no_number_highlight") 96 | " numbers (including longs and complex) 97 | syn match gdscriptNumber "\<0[oO]\=\o\+[Ll]\=\>" 98 | syn match gdscriptNumber "\<0[xX]\x\+[Ll]\=\>" 99 | syn match gdscriptNumber "\<0[bB][01]\+[Ll]\=\>" 100 | syn match gdscriptNumber "\<\%([1-9]\d*\|0\)[Ll]\=\>" 101 | syn match gdscriptNumber "\<\d\+[jJ]\>" 102 | syn match gdscriptNumber "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" 103 | syn match gdscriptNumber 104 | \ "\<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@=" 105 | syn match gdscriptNumber 106 | \ "\%(^\|\W\)\@<=\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" 107 | "endif 108 | 109 | "if exists("gdscript_space_error_highlight") 110 | " trailing whitespace 111 | syn match gdscriptSpaceError display excludenl "\s\+$" 112 | " mixed tabs and spaces 113 | syn match gdscriptSpaceError display " \+\t" 114 | syn match gdscriptSpaceError display "\t\+ " 115 | "endif 116 | 117 | " Sync at the beginning of class, function, or method definition. 118 | syn sync match gdscriptSync grouphere NONE "^\s*\%(master\|slave\|sync\|remote\|func\|class\)\s\+\h\w*\s*(" 119 | 120 | if version >= 508 || !exists("did_gdscript_syn_inits") 121 | if version <= 508 122 | let did_gdscript_syn_inits = 1 123 | command -nargs=+ HiLink hi link 124 | else 125 | command -nargs=+ HiLink hi def link 126 | endif 127 | 128 | " The default highlight links. Can be overridden later. 129 | HiLink gdscriptStatement Statement 130 | HiLink gdscriptConditional Conditional 131 | HiLink gdscriptRepeat Repeat 132 | HiLink gdscriptOperator Operator 133 | "HiLink gdscriptException Exception 134 | HiLink gdscriptInclude Include 135 | HiLink gdscriptDecorator Define 136 | HiLink gdscriptFunction Function 137 | HiLink gdscriptComment Comment 138 | HiLink gdscriptTodo Todo 139 | HiLink gdscriptString String 140 | HiLink gdscriptRawString String 141 | HiLink gdscriptEscape Special 142 | HiLink gdscriptStorage StorageClass 143 | HiLink gdscriptType Type 144 | HiLink gdscriptStructure Structure 145 | "if !exists("gdscript_no_number_highlight") 146 | HiLink gdscriptNumber Number 147 | "endif 148 | "if !exists("gdscript_no_builtin_highlight") 149 | HiLink gdscriptBuiltin Function 150 | "endif 151 | "if exists("gdscript_space_error_highlight") 152 | HiLink gdscriptSpaceError Error 153 | "endif 154 | 155 | delcommand HiLink 156 | endif 157 | 158 | let b:current_syntax = "gdscript" 159 | 160 | let &cpo = s:cpo_save 161 | unlet s:cpo_save 162 | 163 | " vim:set sw=2 sts=2 ts=8 noet: 164 | --------------------------------------------------------------------------------