vim9script if executable('black') &l:formatprg = "black -q - 2>/dev/null" elseif executable('yapf') # pip install yapf &l:formatprg = "yapf" endif setlocal foldignore= b:undo_ftplugin ..= ' | setl foldignore< formatprg<' import autoload 'popup.vim' def PopupHelp(symbol: string) popup.ShowAtCursor(systemlist("python -m pydoc " .. symbol), (winid) => { setbufvar(winbufnr(winid), "&ft", "rst") }) enddef nnoremap exe "Sh python" expand("%:p") \wincmd p b:undo_ftplugin ..= ' | exe "nunmap "' if exists("g:loaded_lsp") setlocal keywordprg=:LspHover nnoremap gd LspGotoDefinition b:undo_ftplugin ..= ' | setl keywordprg<' b:undo_ftplugin ..= ' | exe "nunmap gd"' else nnoremap K PopupHelp(expand("")) xnoremap K yPopupHelp(getreg('"')) b:undo_ftplugin ..= ' | exe "nunmap K"' b:undo_ftplugin ..= ' | exe "xunmap K"' endif def Things() # var things = [] var things = matchbufline(bufnr(), '\v(^\s*(def|class)\s+\k+.*$)|(if __name__ \=\= .*)', 1, '$')->foreach((_, v) => { v.text = $"{v.text} ({v.lnum})" }) popup.FilterMenu("Py Things", things, (res, key) => { exe $":{res.lnum}" normal! zz }, (winid) => { win_execute(winid, $"syn match FilterMenuLineNr '(\\d\\+)$'") win_execute(winid, $"syn match FilterMenuFuncName '\\k\\+\\ze('") hi def link FilterMenuLineNr Comment hi def link FilterMenuFuncName Function }) enddef nnoremap z Things() b:undo_ftplugin ..= ' | exe "nunmap z"'