| 1 |
vim9script |
| 2 |
|
| 3 |
# Open Vim help on {subject} in the current window (rather than a new split) |
| 4 |
# |
| 5 |
# Maintainer: The Vim Project <https://github.com/vim/vim> |
| 6 |
# Last change: 2025 Dec 02 |
| 7 |
|
| 8 |
export def Open(subject: string): void |
| 9 |
|
| 10 |
const HELPCURWIN: func = (): string => { |
| 11 |
if !getcompletion(subject, 'help')->empty() || subject->empty() |
| 12 |
if &buftype != 'help' |
| 13 |
execute 'silent noautocmd keepalt enew' |
| 14 |
setlocal buftype=help noswapfile |
| 15 |
endif |
| 16 |
endif |
| 17 |
return $'help {subject}' |
| 18 |
} |
| 19 |
|
| 20 |
var contmod: bool = true |
| 21 |
if &modified |
| 22 |
echohl MoreMsg |
| 23 |
echo $'Buffer {bufname()} is modified - continue? (y/n)' |
| 24 |
echohl None |
| 25 |
contmod = (getcharstr() == 'y') |
| 26 |
endif |
| 27 |
if contmod |
| 28 |
try |
| 29 |
execute HELPCURWIN() |
| 30 |
catch |
| 31 |
echohl Error |
| 32 |
# {subject} invalid - Echo 'helpcurwin: E149:' (omit 'Vim(help):') |
| 33 |
echo $'helpcurwin: {v:exception->substitute("^[^:]\+:", "", "")}' |
| 34 |
echohl None |
| 35 |
endtry |
| 36 |
else |
| 37 |
echo $'Aborted opening in current window, :help {subject}' |
| 38 |
endif |
| 39 |
|
| 40 |
enddef |
| 41 |
|
| 42 |
# vim: ts=8 sts=2 sw=2 et |