vim9script # https://github.com/habamax/.vim/blob/master/after/ftplugin/vim.vim setl textwidth=80 setl keywordprg=:help setl sw=4 ts=8 sts=4 et iab #--- #------------------------------=abbr#Eatchar() iab augroup abbr#NotCtx('augroup') ? 'augroup' : 'augroup \| autocmd!augroup ENDk_ela=abbr#Eatchar()' iab def abbr#NotCtx('def') ? 'def' : 'def oenddefk_ffla=abbr#Eatchar()' iab def! abbr#NotCtx('def!') ? 'def!' : 'def! oenddefk_ffla=abbr#Eatchar()' iab if abbr#NotCtx('if') ? 'if' : 'if oendifk_ela=abbr#Eatchar()' iab while abbr#NotCtx('while') ? 'while' : 'while oendwhilek_ela=abbr#Eatchar()' iab for abbr#NotCtx('for' ) ? 'for' : 'for oendfork_ela=abbr#Eatchar()' # Convince vim that 'def' is a macro like C's #define setlocal define=^\\s*def b:undo_ftplugin ..= ' | setlocal define<' # setl softtabstop=4 shiftwidth=4 expandtab # exe 'setlocal listchars=tab:\│\ ,multispace:\│' .. repeat('\ ', &sw - 1) .. ',trail:~' if exists('g:loaded_scope') import autoload 'scope/popup.vim' def Things() var things = [] for nr in range(1, line('$')) var line = getline(nr) if line =~ '\(^\|\s\)def \k\+(' || line =~ '\(^\|\s\)class \k\+' || line =~ '\(^\|\s\)fu\%[nction]!\?\s\+\([sgl]:\)\?\k\+(' || line =~ '^\s*com\%[mand]!\?\s\+\S\+' || line =~ '^\s*aug\%[roup]\s\+\S\+' && line !~ '\c^\s*aug\%[roup] end\s*$' if line =~ '^\s*com\%[mand]!\?\s\+\S\+' line = line->substitute(' -\(range\|count\|nargs\)\(=.\)\?', '', 'g') line = line->substitute(' -\(bang\|buffer\)', '', '') line = line->substitute(' -complete=\S\+', '', '') line = line->substitute('^\s*com\%[mand]!\?\s\+\S\+\zs.*', '', '') line = line->substitute('^\s*com\%[mand]!\?\s\+', '', '') endif things->add({text: $"{line} ({nr})", linenr: nr}) endif endfor popup.FilterMenu.new("Vim Things", things, (res, key) => { exe $":{res.linenr}" normal! zz }, (winid, _) => { win_execute(winid, $"syn match FilterMenuLineNr '(\\d\\+)$'") hi def link FilterMenuLineNr Comment }) enddef nnoremap / Things() elseif exists('g:loaded_vimsuggest') # import autoload 'vimsuggest/addons/addons.vim' # command! -nargs=* -complete=customlist,Complete VSArtifacts addons.DoArtifactsAction() # nnoremap / :VSArtifacts # def Complete(A: string, L: string, C: number): list # var patterns = [ # '\(^\|\s\)def\s\+\zs\k\+\ze(', # '\(^\|\s\)fu\%[nction]!\?\s\+\([sgl]:\)\?\zs\k\+\ze(', # '^\s*com\%[mand]!\?\s\+\zs\S\+\ze' # ] # return addons.ArtifactsComplete(A, L, C, patterns) # enddef # :defcompile # Otherwise compile errors within Complete() show up only upon pressing nnoremap / :VSGlobal \v\c(^\s)(deffun%[ction]com%[mand]:?hi%[ghlight])!?\s.{-} nnoremap ? :VSGlobal else def Definitions(): list var items = [] var patterns = [ '\(^\|\s\)def\s\+\zs\k\+\ze(', '\(^\|\s\)fu\%[nction]!\?\s\+\([sgl]:\)\?\zs\k\+\ze(', '^\s*com\%[mand]!\?\s\+\zs\S\+\ze' ] for nr in range(1, line('$')) var line = getline(nr) for pat in patterns var name = line->matchstr(pat) if name != null_string items->add({text: name, lnum: nr}) break endif endfor endfor return items->copy()->filter((_, v) => v !~ '^\s*#') enddef command -buffer -nargs=* -complete=customlist,Completor VimGoTo DoCommand() nnoremap / :VimGoTo def DoCommand(arg: string = null_string) var items = (arg == null_string) ? Definitions() : Definitions()->matchfuzzy(arg, {matchseq: 1, key: 'text'}) if !items->empty() exe $":{items[0].lnum}" normal! zz endif enddef def Completor(arg: string, cmdline: string, cursorpos: number): list var items = (arg == null_string) ? Definitions() : Definitions()->matchfuzzy(arg, {matchseq: 1, key: 'text'}) return items->mapnew((_, v) => v.text) enddef endif