Skip to content

Commit 639d93f

Browse files
Shane-XB-Qianchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 487dd17 commit 639d93f

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enddef
3939
#}}}1
4040
# Core {{{1
4141
def HandlePackaddLine(editcmd: string, curline: string) #{{{2
42-
var pat: string = '^\s*packadd!\=\s\+\zs\S\+$'
42+
var pat: string = '^\s*\%(:\s*\)\=packadd!\=\s\+\zs\S\+$'
4343
var plugin: string = curline
4444
->matchstr(pat)
4545
->substitute('^vim-\|\.vim$', '', 'g')
@@ -53,12 +53,9 @@ def HandlePackaddLine(editcmd: string, curline: string) #{{{2
5353
endtry
5454
else
5555
var split: string = editcmd[0] == 'g' ? 'edit' : editcmd[1] == 'g' ? 'tabedit' : 'split'
56-
# In the past, we passed `runtime` to `getcompletion()`, instead of
57-
# `cmdline`. But the output was tricky to use, because it contained
58-
# paths relative to inconsistent root directories.
59-
var files: list<string> = getcompletion($'edit **/plugin/{plugin}.vim', 'cmdline')
56+
var files: list<string> = getcompletion($'plugin/{plugin}', 'runtime')
57+
->map((_, fname: string) => fname->findfile(&rtp)->fnamemodify(':p'))
6058
->filter((_, path: string): bool => filereadable(path))
61-
->map((_, fname: string) => fname->fnamemodify(':p'))
6259
if empty(files)
6360
echo 'Could not find any plugin file for ' .. string(plugin)
6461
return
@@ -68,7 +65,7 @@ def HandlePackaddLine(editcmd: string, curline: string) #{{{2
6865
enddef
6966

7067
def HandleColoLine(editcmd: string, curline: string) #{{{2
71-
var pat: string = '^\s*colo\%[rscheme]\s\+\zs\S\+$'
68+
var pat: string = '^\s*\%(:\s*\)\=colo\%[rscheme]\s\+\zs\S\+$'
7269
var colo: string = curline->matchstr(pat)
7370

7471
if colo == ''
@@ -93,7 +90,7 @@ enddef
9390

9491
def HandleImportLine(editcmd: string, curline: string) #{{{2
9592
var fname: string
96-
var import_cmd: string = '^\s*import\s\+\%(autoload\s\+\)\='
93+
var import_cmd: string = '^\s*\%(:\s*\)\=import\s\+\%(autoload\s\+\)\='
9794
var import_alias: string = '\%(\s\+as\s\+\w\+\)\=$'
9895
var import_string: string = import_cmd .. '\([''"]\)\zs.*\ze\1' .. import_alias
9996
var import_expr: string = import_cmd .. '\zs.*\ze' .. import_alias

runtime/ftplugin/vim.vim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
" Last Change: 2025 Aug 07
1010
" 2025 Aug 06 by Vim Project (add gf maps #17881)
1111
" 2025 Aug 08 by Vim Project (add Vim script complete function #17871)
12+
" 2025 Aug 12 by Vim Project (improve vimgoto script #17970))
1213

1314
" Only do this when not done yet for this buffer
1415
if exists("b:did_ftplugin")
@@ -152,7 +153,7 @@ if !exists("no_plugin_maps") && !exists("no_vim_maps")
152153
nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
153154
xnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
154155
155-
" Purpose: Handle `:import` and `:packadd` lines in a smarter way. {{{
156+
" Purpose: Handle :import, :colorscheme and :packadd lines in a smarter way. {{{
156157
"
157158
" `:import` is followed by a filename or filepath. Find it.
158159
"
@@ -171,9 +172,10 @@ if !exists("no_plugin_maps") && !exists("no_vim_maps")
171172
" buffer.
172173
" }}}
173174
" We use the `F` variants, instead of the `f` ones, because they're smarter.
174-
nnoremap <silent><buffer> gf :<C-U>call vim#Find('gF')<CR>
175-
nnoremap <silent><buffer> <C-W>f :<C-U>call vim#Find("\<lt>C-W>F")<CR>
176-
nnoremap <silent><buffer> <C-W>gf :<C-U>call vim#Find("\<lt>C-W>gF")<CR>
175+
" See $VIMRUNTIME/autoload/vimgoto.vim
176+
nnoremap <silent><buffer> gf :<C-U>call vimgoto#Find('gF')<CR>
177+
nnoremap <silent><buffer> <C-W>f :<C-U>call vimgoto#Find("\<lt>C-W>F")<CR>
178+
nnoremap <silent><buffer> <C-W>gf :<C-U>call vimgoto#Find("\<lt>C-W>gF")<CR>
177179
endif
178180

179181
" Let the matchit plugin know what items can be matched.

0 commit comments

Comments
 (0)