blob: 3edbb27e785ec9658720baef28dc15bce26dffe2 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
2" Language: man
Bram Moolenaar7ceefb32020-05-01 16:07:38 +02003" Maintainer: Jason Franklin <vim@justemail.net>
Bram Moolenaar2cfb4a22020-05-07 18:56:00 +02004" Maintainer: SungHyun Nam <goweol@gmail.com>
Bram Moolenaard799daa2022-06-20 11:17:32 +01005" Autoload Split: Bram Moolenaar
Christian Brabandt6dcd7f12024-06-06 19:06:38 +02006" Last Change: 2024 Jun 06 (disabled the q mapping, #8210)
Ivan Shapovalov84ca1382024-07-06 16:56:02 +02007" 2024 Jul 06 (use nnoremap, #15130)
John M Devin5d1c5512024-08-23 18:34:41 +02008" 2024 Aug 23 (improve the <Plug>ManBS mapping, #15547, #15556)
David Mandelbergc2623822025-03-10 21:26:50 +01009" 2025 Mar 09 (improve :Man completion for man-db, #16843)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
11" To make the ":Man" command available before editing a manual page, source
12" this script from your startup vimrc file.
13
Bram Moolenaard799daa2022-06-20 11:17:32 +010014" If 'filetype' isn't "man", we must have been called to define ":Man" and not
15" to do the filetype plugin stuff.
Bram Moolenaar071d4272004-06-13 20:20:40 +000016if &filetype == "man"
17
18 " Only do this when not done yet for this buffer
19 if exists("b:did_ftplugin")
20 finish
21 endif
22 let b:did_ftplugin = 1
Bram Moolenaar91f84f62018-07-29 15:07:52 +020023endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000024
Bram Moolenaar91f84f62018-07-29 15:07:52 +020025let s:cpo_save = &cpo
26set cpo-=C
27
David Mandelbergc2623822025-03-10 21:26:50 +010028if !exists('g:ft_man_implementation')
29 if executable('mandb') > 0
30 let g:ft_man_implementation = 'man-db'
31 else
32 let g:ft_man_implementation = ''
33 endif
34endif
35
Bram Moolenaar91f84f62018-07-29 15:07:52 +020036if &filetype == "man"
Bram Moolenaarf269eab2022-10-03 18:04:35 +010037 " Allow hyphen, plus, colon, dot, and commercial at in manual page name.
Bram Moolenaar71badf92023-04-22 22:40:14 +010038 " Parentheses are not here but in dist#man#PreGetPage()
39 setlocal iskeyword=48-57,_,a-z,A-Z,-,+,:,.,@-@
Bram Moolenaar91f84f62018-07-29 15:07:52 +020040 let b:undo_ftplugin = "setlocal iskeyword<"
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
42 " Add mappings, unless the user didn't want this.
43 if !exists("no_plugin_maps") && !exists("no_man_maps")
44 if !hasmapto('<Plug>ManBS')
45 nmap <buffer> <LocalLeader>h <Plug>ManBS
Bram Moolenaar91f84f62018-07-29 15:07:52 +020046 let b:undo_ftplugin = b:undo_ftplugin
47 \ . '|silent! nunmap <buffer> <LocalLeader>h'
Bram Moolenaar071d4272004-06-13 20:20:40 +000048 endif
John M Devin5d1c5512024-08-23 18:34:41 +020049
50 nnoremap <buffer> <silent> <Plug>ManBS :setl ma<Bar>%s/.\b//g
51 \ <Bar>setl noma<CR>`'
Bram Moolenaar071d4272004-06-13 20:20:40 +000052
Bram Moolenaard799daa2022-06-20 11:17:32 +010053 nnoremap <buffer> <silent> <c-]> :call dist#man#PreGetPage(v:count)<CR>
54 nnoremap <buffer> <silent> <c-t> :call dist#man#PopPage()<CR>
Bram Moolenaar91f84f62018-07-29 15:07:52 +020055
56 " Add undo commands for the maps
57 let b:undo_ftplugin = b:undo_ftplugin
58 \ . '|silent! nunmap <buffer> <Plug>ManBS'
59 \ . '|silent! nunmap <buffer> <c-]>'
60 \ . '|silent! nunmap <buffer> <c-t>'
Bram Moolenaard042dc82015-11-24 19:18:36 +010061 endif
62
63 if exists('g:ft_man_folding_enable') && (g:ft_man_folding_enable == 1)
64 setlocal foldmethod=indent foldnestmax=1 foldenable
Bram Moolenaar91f84f62018-07-29 15:07:52 +020065 let b:undo_ftplugin = b:undo_ftplugin
66 \ . '|silent! setl fdm< fdn< fen<'
Bram Moolenaar071d4272004-06-13 20:20:40 +000067 endif
68
69endif
70
71if exists(":Man") != 2
David Mandelbergc2623822025-03-10 21:26:50 +010072 if g:ft_man_implementation ==# 'man-db'
73 com -nargs=+ -complete=customlist,dist#man#ManDbComplete Man call dist#man#GetPage(<q-mods>, <f-args>)
74 else
75 com -nargs=+ -complete=shellcmd Man call dist#man#GetPage(<q-mods>, <f-args>)
76 endif
Ivan Shapovalovf21ca6d2024-07-06 16:16:40 +020077 nnoremap <Leader>K :call dist#man#PreGetPage(0)<CR>
78 nnoremap <Plug>ManPreGetPage :call dist#man#PreGetPage(0)<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +000079endif
80
David Mandelbergc2623822025-03-10 21:26:50 +010081if exists(":ManReload") != 2
82 com ManReload call dist#man#Reload()
83endif
84
Bram Moolenaar91f84f62018-07-29 15:07:52 +020085let &cpo = s:cpo_save
86unlet s:cpo_save
87
Bram Moolenaarddf8d1c2016-06-20 11:22:54 +020088" vim: set sw=2 ts=8 noet: