|
1 | 1 | " Vim filetype plugin |
2 | 2 | " Language: Vim |
3 | 3 | " Maintainer: Doug Kearns <dougkearns@gmail.com> |
| 4 | +" Last Change: 2025 Aug 07 |
4 | 5 | " Former Maintainer: Bram Moolenaar <Bram@vim.org> |
5 | | -" Contributors: Riley Bruins <ribru17@gmail.com> ('commentstring'), |
| 6 | +" Contributors: Riley Bruins <ribru17@gmail.com> ('commentstring') |
6 | 7 | " @Konfekt |
7 | 8 | " @tpope (s:Help()) |
8 | 9 | " @lacygoill |
@@ -62,41 +63,42 @@ if !exists("*" .. expand("<SID>") .. "Help") |
62 | 63 | function s:Help(topic) abort |
63 | 64 | let topic = a:topic |
64 | 65 |
|
| 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 | + |
65 | 77 | if get(g:, 'syntax_on', 0) |
66 | 78 | let syn = synIDattr(synID(line('.'), col('.'), 1), 'name') |
67 | 79 | 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 |
75 | 87 | endif |
76 | 88 | endif |
77 | 89 |
|
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 |
92 | 92 | elseif pre =~# '\<v:$' |
93 | | - return 'v:'.topic |
| 93 | + return 'v:' .. topic |
94 | 94 | elseif pre =~# '<$' |
95 | | - return '<'.topic.'>' |
| 95 | + return '<' .. topic .. '>' |
96 | 96 | elseif pre =~# '\\$' |
97 | | - return '/\'.topic |
| 97 | + return '/\' .. topic |
98 | 98 | elseif topic ==# 'v' && post =~# ':\w\+' |
99 | | - return 'v'.matchstr(post, ':\w\+') |
| 99 | + return 'v' .. matchstr(post, ':\w\+') |
| 100 | + elseif pre =~# '&\%([lg]:\)\=$' |
| 101 | + return "'" .. topic .. "'" |
100 | 102 | else |
101 | 103 | return topic |
102 | 104 | endif |
|
0 commit comments