29996
|
1 vim9script
|
|
2
|
|
3 # Vim filetype plugin file
|
|
4 # Language: gdscript (Godot game engine scripting language)
|
|
5 # Maintainer: Maxim Kim <habamax@gmail.com>
|
30085
|
6 # Website: https://github.com/habamax/vim-gdscript
|
29996
|
7
|
|
8 if exists("b:did_ftplugin") | finish | endif
|
|
9
|
|
10 b:did_ftplugin = 1
|
|
11 b:undo_ftplugin = 'setlocal cinkeys<'
|
|
12 \ .. '| setlocal indentkeys<'
|
|
13 \ .. '| setlocal commentstring<'
|
|
14 \ .. '| setlocal suffixesadd<'
|
|
15 \ .. '| setlocal foldexpr<'
|
|
16 \ .. '| setlocal foldignore<'
|
|
17
|
|
18 setlocal cinkeys-=0#
|
|
19 setlocal indentkeys-=0#
|
|
20 setlocal suffixesadd=.gd
|
|
21 setlocal commentstring=#\ %s
|
|
22 setlocal foldignore=
|
|
23 setlocal foldexpr=GDScriptFoldLevel()
|
|
24
|
|
25
|
|
26 def GDScriptFoldLevel(): string
|
|
27 var line = getline(v:lnum)
|
|
28 if line =~? '^\s*$'
|
|
29 return "-1"
|
|
30 endif
|
|
31
|
|
32 var sw = shiftwidth()
|
|
33 var indent = indent(v:lnum) / sw
|
|
34 var indent_next = indent(nextnonblank(v:lnum + 1)) / sw
|
|
35
|
|
36 if indent_next > indent && line =~ ':\s*$'
|
|
37 return $">{indent_next}"
|
|
38 else
|
|
39 return $"{indent}"
|
|
40 endif
|
|
41 enddef
|
|
42
|
|
43
|
30324
|
44 if !exists("g:no_plugin_maps")
|
|
45 # Next/Previous section
|
|
46 def NextSection(back: bool, cnt: number)
|
|
47 for n in range(cnt)
|
|
48 search('^\s*func\s', back ? 'bW' : 'W')
|
|
49 endfor
|
|
50 enddef
|
29996
|
51
|
30324
|
52 nnoremap <silent><buffer> ]] <scriptcmd>NextSection(false, v:count1)<CR>
|
|
53 nnoremap <silent><buffer> [[ <scriptcmd>NextSection(true, v:count1)<CR>
|
|
54 xmap <buffer><expr> ]] $'<C-\><C-N>{v:count1}]]m>gv'
|
|
55 xmap <buffer><expr> [[ $'<C-\><C-N>{v:count1}[[m>gv'
|
|
56 b:undo_ftplugin ..=
|
|
57 \ " | silent exe 'unmap <buffer> [['"
|
|
58 \ .. " | silent exe 'unmap <buffer> ]]'"
|
|
59 endif
|