Skip to content

Commit 487dd17

Browse files
Shane-XB-Qianchrisbra
authored andcommitted
runtime(vim): cannot jump to :colorscheme files
Problem: cannot jump to :colorscheme files Solution: Let runtime/autoload/vim.vim handle :colorscheme lines closes: #17971 Signed-off-by: Shane-XB-Qian <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 397b9da commit 487dd17

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

runtime/autoload/vim.vim

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
vim9script
22

3+
# Language: Vim9 script
4+
# Contributers: @lacygoill
5+
# Shane-XB-Qian
6+
# Last Change: 2025 Aug 12
7+
#
8+
# Vim Script to handle
9+
# :import, :packadd and :colorscheme
10+
# lines and allows to easily jump to it using gf
11+
#
12+
# see runtime/ftplugin/vim.vim
13+
314
# Interface {{{1
415
export def Find(editcmd: string) #{{{2
516
var curline: string = getline('.')
@@ -9,6 +20,11 @@ export def Find(editcmd: string) #{{{2
920
return
1021
endif
1122

23+
if curline =~ '^\s*\%(:\s*\)\=colo\%[rscheme]\s'
24+
HandleColoLine(editcmd, curline)
25+
return
26+
endif
27+
1228
if curline =~ '^\s*\%(:\s*\)\=import\s'
1329
HandleImportLine(editcmd, curline)
1430
return
@@ -51,6 +67,30 @@ def HandlePackaddLine(editcmd: string, curline: string) #{{{2
5167
endif
5268
enddef
5369

70+
def HandleColoLine(editcmd: string, curline: string) #{{{2
71+
var pat: string = '^\s*colo\%[rscheme]\s\+\zs\S\+$'
72+
var colo: string = curline->matchstr(pat)
73+
74+
if colo == ''
75+
try
76+
execute 'normal! ' .. editcmd .. 'zv'
77+
catch
78+
Error(v:exception)
79+
return
80+
endtry
81+
else
82+
var split: string = editcmd[0] == 'g' ? 'edit' : editcmd[1] == 'g' ? 'tabedit' : 'split'
83+
var files: list<string> = getcompletion($'colors/{colo}', 'runtime')
84+
->map((_, fname: string) => fname->findfile(&rtp)->fnamemodify(':p'))
85+
->filter((_, path: string): bool => filereadable(path))
86+
if empty(files)
87+
echo 'Could not find any colorscheme file for ' .. string(colo)
88+
return
89+
endif
90+
files->Open(split)
91+
endif
92+
enddef
93+
5494
def HandleImportLine(editcmd: string, curline: string) #{{{2
5595
var fname: string
5696
var import_cmd: string = '^\s*import\s\+\%(autoload\s\+\)\='
@@ -132,3 +172,5 @@ def Error(msg: string) #{{{2
132172
echomsg msg
133173
echohl NONE
134174
enddef
175+
176+
# vim: sw=4 et

0 commit comments

Comments
 (0)