gdscript.vim 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. " Vim filetype plugin file
  2. " Language: gdscript (Godot game engine scripting language)
  3. " Maintainer: Maxim Kim <habamax@gmail.com>
  4. " Website: https://github.com/habamax/vim-gdscript
  5. "
  6. " This file has been manually translated from Vim9 script.
  7. if exists("b:did_ftplugin") | finish | endif
  8. let s:save_cpo = &cpo
  9. set cpo&vim
  10. let b:did_ftplugin = 1
  11. let b:undo_ftplugin = 'setlocal cinkeys<'
  12. \ .. '| setlocal indentkeys<'
  13. \ .. '| setlocal commentstring<'
  14. \ .. '| setlocal suffixesadd<'
  15. \ .. '| setlocal foldexpr<'
  16. \ .. '| setlocal foldignore<'
  17. setlocal cinkeys-=0#
  18. setlocal indentkeys-=0#
  19. setlocal suffixesadd=.gd
  20. setlocal commentstring=#\ %s
  21. setlocal foldignore=
  22. setlocal foldexpr=s:GDScriptFoldLevel()
  23. if get(g:, 'gdscript_recommended_style', 1)
  24. setlocal noexpandtab tabstop=4 softtabstop=0 shiftwidth=0
  25. let b:undo_ftplugin ..= ' | setlocal expandtab< tabstop< softtabstop< shiftwidth<'
  26. endif
  27. function s:GDScriptFoldLevel() abort
  28. let line = getline(v:lnum)
  29. if line =~? '^\s*$'
  30. return "-1"
  31. endif
  32. let sw = shiftwidth()
  33. let indent = indent(v:lnum) / sw
  34. let indent_next = indent(nextnonblank(v:lnum + 1)) / sw
  35. if indent_next > indent && line =~# ':\s*$'
  36. return $">{indent_next}"
  37. else
  38. return $"{indent}"
  39. endif
  40. endfunction
  41. if !exists("g:no_plugin_maps")
  42. " Next/Previous section
  43. function s:NextSection(back, cnt) abort
  44. for n in range(a:cnt)
  45. call search('^\s*func\s', a:back ? 'bW' : 'W')
  46. endfor
  47. endfunction
  48. " Nvim: <scriptcmd> hasn't been ported yet.
  49. " nnoremap <silent><buffer> ]] <scriptcmd>NextSection(false, v:count1)<CR>
  50. " nnoremap <silent><buffer> [[ <scriptcmd>NextSection(true, v:count1)<CR>
  51. nnoremap <silent><buffer> ]] <Cmd>call <SID>NextSection(v:false, v:count1)<CR>
  52. nnoremap <silent><buffer> [[ <Cmd>call <SID>NextSection(v:true, v:count1)<CR>
  53. xmap <buffer><expr> ]] $'<C-\><C-N>{v:count1}]]m>gv'
  54. xmap <buffer><expr> [[ $'<C-\><C-N>{v:count1}[[m>gv'
  55. let b:undo_ftplugin ..=
  56. \ " | silent exe 'unmap <buffer> [['"
  57. \ .. " | silent exe 'unmap <buffer> ]]'"
  58. endif
  59. let &cpo = s:save_cpo
  60. unlet s:save_cpo