gdscript.vim 1.6 KB

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