Skip to content

Commit c65643c

Browse files
dkearnschrisbra
authored andcommitted
runtime(vim): Update ftplugin, fix option variable 'keywordprg' matching
- Match &option, and &[lg]:option variables. - Match Ex commands after :bar. - Fix matching of pre and post context text. - Style - use '..' for string concatenation. fixes #17567 closes: #17653 Signed-off-by: Doug Kearns <dougkearns@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 7270a5a commit c65643c

1 file changed

Lines changed: 28 additions & 26 deletions

File tree

runtime/ftplugin/vim.vim

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
" Vim filetype plugin
22
" Language: Vim
33
" Maintainer: Doug Kearns <dougkearns@gmail.com>
4+
" Last Change: 2025 Aug 07
45
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
5-
" Contributors: Riley Bruins <ribru17@gmail.com> ('commentstring'),
6+
" Contributors: Riley Bruins <ribru17@gmail.com> ('commentstring')
67
" @Konfekt
78
" @tpope (s:Help())
89
" @lacygoill
@@ -62,41 +63,42 @@ if !exists("*" .. expand("<SID>") .. "Help")
6263
function s:Help(topic) abort
6364
let topic = a:topic
6465

66+
" keyword is not necessarily under the cursor, see :help K
67+
let line = getline('.')
68+
let i = match(line, '\V' .. escape(topic, '\'), col('.') - len(topic))
69+
let pre = strpart(line, 0, i)
70+
let post = strpart(line, i + len(topic))
71+
72+
" local/global option vars
73+
if topic =~# '[lg]' && pre ==# '&' && post =~# ':\k\+'
74+
let topic = matchstr(post, '\k\+')
75+
endif
76+
6577
if get(g:, 'syntax_on', 0)
6678
let syn = synIDattr(synID(line('.'), col('.'), 1), 'name')
6779
if syn ==# 'vimFuncName'
68-
return topic.'()'
69-
elseif syn ==# 'vimOption'
70-
return "'".topic."'"
71-
elseif syn ==# 'vimUserAttrbKey'
72-
return ':command-'.topic
73-
elseif syn =~# 'vimCommand'
74-
return ':'.topic
80+
return topic .. '()'
81+
elseif syn ==# 'vimOption' || syn ==# 'vimOptionVarName'
82+
return "'" .. topic .. "'"
83+
elseif syn ==# 'vimUserCmdAttrKey'
84+
return ':command-' .. topic
85+
elseif syn ==# 'vimCommand'
86+
return ':' .. topic
7587
endif
7688
endif
7789

78-
let col = col('.') - 1
79-
while col && getline('.')[col] =~# '\k'
80-
let col -= 1
81-
endwhile
82-
let pre = col == 0 ? '' : getline('.')[0 : col]
83-
84-
let col = col('.') - 1
85-
while col && getline('.')[col] =~# '\k'
86-
let col += 1
87-
endwhile
88-
let post = getline('.')[col : -1]
89-
90-
if pre =~# '^\s*:\=$'
91-
return ':'.topic
90+
if pre =~# '^\s*:\=$' || pre =~# '\%(\\\||\)\@<!|\s*:\=$'
91+
return ':' .. topic
9292
elseif pre =~# '\<v:$'
93-
return 'v:'.topic
93+
return 'v:' .. topic
9494
elseif pre =~# '<$'
95-
return '<'.topic.'>'
95+
return '<' .. topic .. '>'
9696
elseif pre =~# '\\$'
97-
return '/\'.topic
97+
return '/\' .. topic
9898
elseif topic ==# 'v' && post =~# ':\w\+'
99-
return 'v'.matchstr(post, ':\w\+')
99+
return 'v' .. matchstr(post, ':\w\+')
100+
elseif pre =~# '&\%([lg]:\)\=$'
101+
return "'" .. topic .. "'"
100102
else
101103
return topic
102104
endif

0 commit comments

Comments
 (0)