Skip to content

Commit 0b540c6

Browse files
brianhusterchrisbra
andcommitted
runtime(help): add omni completion and 'iskeyword' to filetype plugin
Problem: - Help tags provide a good way to navigate the Vim documentation, but many help documents don't use them effectively. I think one of the reasons is that help writers have to look up help tags manually with `:help` command, which is not very convenient. - 'iskeyword' is only set for help buffers opened by `:help` command. That means if I'm editing a help file, I cannot jump to tag in same file using `Ctrl-]` unless I manually set it, which is annoying. Solution: - Add omni completion for Vim help tags. - Set 'iskeyword' for `ft-help` closes: #17073 Co-authored-by: Christian Brabandt <cb@256bit.org> Signed-off-by: Phạm Bình An <phambinhanctb2004@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 7517a8c commit 0b540c6

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

runtime/doc/helphelp.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*helphelp.txt* For Vim version 9.1. Last change: 2025 Jan 11
1+
*helphelp.txt* For Vim version 9.1. Last change: 2025 Apr 08
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -471,8 +471,13 @@ highlighting. So do these:
471471
You can find the details in $VIMRUNTIME/syntax/help.vim
472472

473473

474-
GENDER NEUTRAL LANGUAGE
474+
FILETYPE COMPLETION *ft-help-omni*
475+
476+
To get completion for help tags when writing a tag reference, you can use the
477+
|i_CTRL-X_CTRL-O| command.
475478

479+
480+
GENDER NEUTRAL LANGUAGE
476481
*gender-neutral* *inclusion*
477482
Vim is for everybody, no matter race, gender or anything. For new or updated
478483
help text, gender neutral language is recommended. Some of the help text is

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7394,6 +7394,7 @@ ft-groff-syntax syntax.txt /*ft-groff-syntax*
73947394
ft-gsp-syntax syntax.txt /*ft-gsp-syntax*
73957395
ft-hare filetype.txt /*ft-hare*
73967396
ft-haskell-syntax syntax.txt /*ft-haskell-syntax*
7397+
ft-help-omni helphelp.txt /*ft-help-omni*
73977398
ft-html-indent indent.txt /*ft-html-indent*
73987399
ft-html-omni insert.txt /*ft-html-omni*
73997400
ft-html-syntax syntax.txt /*ft-html-syntax*

runtime/ftplugin/help.vim

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
" Vim filetype plugin file
22
" Language: Vim help file
33
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
4-
" Latest Revision: 2018-12-29
4+
" Last Change: 2025 Apr 08
5+
" 2025 Apr 08 by Vim project (set 'omnifunc' and 'iskeyword', #17073)
56

67
if exists("b:did_ftplugin")
78
finish
@@ -11,12 +12,33 @@ let b:did_ftplugin = 1
1112
let s:cpo_save = &cpo
1213
set cpo&vim
1314

14-
let b:undo_ftplugin = "setl fo< tw< cole< cocu< keywordprg<"
15+
let b:undo_ftplugin = "setl isk< fo< tw< cole< cocu< keywordprg< omnifunc<"
1516

16-
setlocal formatoptions+=tcroql textwidth=78 keywordprg=:help
17+
setlocal formatoptions+=tcroql textwidth=78 keywordprg=:help omnifunc=s:HelpComplete
18+
let &l:iskeyword='!-~,^*,^|,^",192-255'
1719
if has("conceal")
1820
setlocal cole=2 cocu=nc
1921
endif
2022

23+
if !exists('*s:HelpComplete')
24+
func s:HelpComplete(findstart, base)
25+
if a:findstart
26+
let colnr = col('.') - 1 " Get the column number before the cursor
27+
let line = getline('.')
28+
for i in range(colnr - 1, 0, -1)
29+
if line[i] ==# '|'
30+
return i + 1 " Don't include the `|` in base
31+
elseif line[i] ==# "'"
32+
return i " Include the `'` in base
33+
endif
34+
endfor
35+
else
36+
return taglist('^' .. a:base)
37+
\ ->map({_, item -> #{word: item->get('name'), kind: item->get('kind')}})
38+
\ ->extend(getcompletion(a:base, 'help'))
39+
endif
40+
endfunc
41+
endif
42+
2143
let &cpo = s:cpo_save
2244
unlet s:cpo_save

0 commit comments

Comments
 (0)