neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

gdscript.vim (2207B)


      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 
      8 if exists("b:did_ftplugin") | finish | endif
      9 
     10 let s:save_cpo = &cpo
     11 set cpo&vim
     12 
     13 let b:did_ftplugin = 1
     14 let b:undo_ftplugin = 'setlocal cinkeys<'
     15      \ .. '| setlocal indentkeys<'
     16      \ .. '| setlocal commentstring<'
     17      \ .. '| setlocal suffixesadd<'
     18      \ .. '| setlocal foldexpr<'
     19      \ .. '| setlocal foldignore<'
     20 
     21 setlocal cinkeys-=0#
     22 setlocal indentkeys-=0#
     23 setlocal suffixesadd=.gd
     24 setlocal commentstring=#\ %s
     25 setlocal foldignore=
     26 setlocal foldexpr=s:GDScriptFoldLevel()
     27 
     28 if get(g:, 'gdscript_recommended_style', 1)
     29    setlocal noexpandtab tabstop=4 softtabstop=0 shiftwidth=0
     30    let b:undo_ftplugin ..= ' | setlocal expandtab< tabstop< softtabstop< shiftwidth<'
     31 endif
     32 
     33 
     34 function s:GDScriptFoldLevel() abort
     35    let line = getline(v:lnum)
     36    if line =~? '^\s*$'
     37        return "-1"
     38    endif
     39 
     40    let sw = shiftwidth()
     41    let indent = indent(v:lnum) / sw
     42    let indent_next = indent(nextnonblank(v:lnum + 1)) / sw
     43 
     44    if indent_next > indent && line =~# ':\s*$'
     45        return $">{indent_next}"
     46    else
     47        return $"{indent}"
     48    endif
     49 endfunction
     50 
     51 
     52 if !exists("g:no_plugin_maps")
     53    " Next/Previous section
     54    function s:NextSection(back, cnt) abort
     55        for n in range(a:cnt)
     56            call search('^\s*func\s', a:back ? 'bW' : 'W')
     57        endfor
     58    endfunction
     59 
     60    " Nvim: <scriptcmd> hasn't been ported yet.
     61    " nnoremap <silent><buffer> ]] <scriptcmd>NextSection(false, v:count1)<CR>
     62    " nnoremap <silent><buffer> [[ <scriptcmd>NextSection(true, v:count1)<CR>
     63    nnoremap <silent><buffer> ]] <Cmd>call <SID>NextSection(v:false, v:count1)<CR>
     64    nnoremap <silent><buffer> [[ <Cmd>call <SID>NextSection(v:true, v:count1)<CR>
     65    xmap <buffer><expr> ]] $'<C-\><C-N>{v:count1}]]m>gv'
     66    xmap <buffer><expr> [[ $'<C-\><C-N>{v:count1}[[m>gv'
     67    let b:undo_ftplugin ..=
     68          \    " | silent exe 'unmap <buffer> [['"
     69          \ .. " | silent exe 'unmap <buffer> ]]'"
     70 endif
     71 
     72 let &cpo = s:save_cpo
     73 unlet s:save_cpo