From 639d93fc0efe925ec87f31db7f3ccdc0add4e247 Mon Sep 17 00:00:00 2001 From: Shane-XB-Qian Date: Tue, 12 Aug 2025 21:28:28 +0200 Subject: [PATCH] runetime(vim): gf maybe hang and fail * searching'**' maybe terrible slow * searching '**/plugin/' maybe fail * the pattern for the :packadd/:import/:colorscheme did not consistently check for a colon, so always use '\%(:\s*\)\=' before the actual ex command While at it rename the generic name vim.vim to vimgoto.vim as this more clearly states what this script is for. Signed-off-by: Shane-XB-Qian Signed-off-by: Christian Brabandt --- runtime/autoload/{vim.vim => vimgoto.vim} | 13 +++++-------- runtime/ftplugin/vim.vim | 10 ++++++---- 2 files changed, 11 insertions(+), 12 deletions(-) rename runtime/autoload/{vim.vim => vimgoto.vim} (89%) diff --git a/runtime/autoload/vim.vim b/runtime/autoload/vimgoto.vim similarity index 89% rename from runtime/autoload/vim.vim rename to runtime/autoload/vimgoto.vim index c517b756fe..b34dcc1a13 100644 --- a/runtime/autoload/vim.vim +++ b/runtime/autoload/vimgoto.vim @@ -39,7 +39,7 @@ enddef #}}}1 # Core {{{1 def HandlePackaddLine(editcmd: string, curline: string) #{{{2 - var pat: string = '^\s*packadd!\=\s\+\zs\S\+$' + var pat: string = '^\s*\%(:\s*\)\=packadd!\=\s\+\zs\S\+$' var plugin: string = curline ->matchstr(pat) ->substitute('^vim-\|\.vim$', '', 'g') @@ -53,12 +53,9 @@ def HandlePackaddLine(editcmd: string, curline: string) #{{{2 endtry else var split: string = editcmd[0] == 'g' ? 'edit' : editcmd[1] == 'g' ? 'tabedit' : 'split' - # In the past, we passed `runtime` to `getcompletion()`, instead of - # `cmdline`. But the output was tricky to use, because it contained - # paths relative to inconsistent root directories. - var files: list = getcompletion($'edit **/plugin/{plugin}.vim', 'cmdline') + var files: list = getcompletion($'plugin/{plugin}', 'runtime') + ->map((_, fname: string) => fname->findfile(&rtp)->fnamemodify(':p')) ->filter((_, path: string): bool => filereadable(path)) - ->map((_, fname: string) => fname->fnamemodify(':p')) if empty(files) echo 'Could not find any plugin file for ' .. string(plugin) return @@ -68,7 +65,7 @@ def HandlePackaddLine(editcmd: string, curline: string) #{{{2 enddef def HandleColoLine(editcmd: string, curline: string) #{{{2 - var pat: string = '^\s*colo\%[rscheme]\s\+\zs\S\+$' + var pat: string = '^\s*\%(:\s*\)\=colo\%[rscheme]\s\+\zs\S\+$' var colo: string = curline->matchstr(pat) if colo == '' @@ -93,7 +90,7 @@ enddef def HandleImportLine(editcmd: string, curline: string) #{{{2 var fname: string - var import_cmd: string = '^\s*import\s\+\%(autoload\s\+\)\=' + var import_cmd: string = '^\s*\%(:\s*\)\=import\s\+\%(autoload\s\+\)\=' var import_alias: string = '\%(\s\+as\s\+\w\+\)\=$' var import_string: string = import_cmd .. '\([''"]\)\zs.*\ze\1' .. import_alias var import_expr: string = import_cmd .. '\zs.*\ze' .. import_alias diff --git a/runtime/ftplugin/vim.vim b/runtime/ftplugin/vim.vim index 9b0f89dbef..22b2614658 100644 --- a/runtime/ftplugin/vim.vim +++ b/runtime/ftplugin/vim.vim @@ -9,6 +9,7 @@ " Last Change: 2025 Aug 07 " 2025 Aug 06 by Vim Project (add gf maps #17881) " 2025 Aug 08 by Vim Project (add Vim script complete function #17871) +" 2025 Aug 12 by Vim Project (improve vimgoto script #17970)) " Only do this when not done yet for this buffer if exists("b:did_ftplugin") @@ -152,7 +153,7 @@ if !exists("no_plugin_maps") && !exists("no_vim_maps") nnoremap [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW") xnoremap [" :exe "normal! gv"call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW") - " Purpose: Handle `:import` and `:packadd` lines in a smarter way. {{{ + " Purpose: Handle :import, :colorscheme and :packadd lines in a smarter way. {{{ " " `:import` is followed by a filename or filepath. Find it. " @@ -171,9 +172,10 @@ if !exists("no_plugin_maps") && !exists("no_vim_maps") " buffer. " }}} " We use the `F` variants, instead of the `f` ones, because they're smarter. - nnoremap gf :call vim#Find('gF') - nnoremap f :call vim#Find("\C-W>F") - nnoremap gf :call vim#Find("\C-W>gF") + " See $VIMRUNTIME/autoload/vimgoto.vim + nnoremap gf :call vimgoto#Find('gF') + nnoremap f :call vimgoto#Find("\C-W>F") + nnoremap gf :call vimgoto#Find("\C-W>gF") endif " Let the matchit plugin know what items can be matched.