blob: d268bfee7ad503e14022904a7852c9f51ba8dc48 [file] [log] [blame]
Bram Moolenaar60cce2f2015-10-13 23:21:27 +02001" Vim filetype plugin file
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +02002" Language: systemd.unit(5)
3" Keyword Lookup Support: Enno Nagel <enno.nagel+vim@gmail.com>
Enno1e33cd72023-10-08 19:14:07 +02004" Latest Revision: 2023-10-07
Bram Moolenaar60cce2f2015-10-13 23:21:27 +02005
Enno5036e692023-10-18 11:38:19 +02006if exists("b:did_ftplugin")
7 finish
Bram Moolenaar60cce2f2015-10-13 23:21:27 +02008endif
Enno5036e692023-10-18 11:38:19 +02009" Looks a lot like dosini files.
10runtime! ftplugin/dosini.vim
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020011
Enno2f25e402023-08-23 21:27:50 +020012if has('unix') && executable('less')
13 if !has('gui_running')
Enno1e33cd72023-10-08 19:14:07 +020014 command -buffer -nargs=1 SystemdKeywordPrg silent exe '!' . KeywordLookup_systemd(<q-args>) | redraw!
Enno2f25e402023-08-23 21:27:50 +020015 elseif has('terminal')
Enno1e33cd72023-10-08 19:14:07 +020016 command -buffer -nargs=1 SystemdKeywordPrg silent exe 'term ' . KeywordLookup_systemd(<q-args>)
Enno2f25e402023-08-23 21:27:50 +020017 endif
Enno1e33cd72023-10-08 19:14:07 +020018 if exists(':SystemdKeywordPrg') == 2
Enno2f25e402023-08-23 21:27:50 +020019 if !exists('*KeywordLookup_systemd')
20 function KeywordLookup_systemd(keyword) abort
21 let matches = matchlist(getline(search('\v^\s*\[\s*.+\s*\]\s*$', 'nbWz')), '\v^\s*\[\s*(\k+).*\]\s*$')
22 if len(matches) > 1
23 let section = matches[1]
24 return 'LESS= MANPAGER="less --pattern=''(^|,)\s+' . a:keyword . '=$'' --hilite-search" man ' . 'systemd.' . section
25 else
26 return 'LESS= MANPAGER="less --pattern=''(^|,)\s+' . a:keyword . '=$'' --hilite-search" man ' . 'systemd'
27 endif
28 endfunction
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020029 endif
Enno2f25e402023-08-23 21:27:50 +020030 setlocal iskeyword+=-
Enno1e33cd72023-10-08 19:14:07 +020031 setlocal keywordprg=:SystemdKeywordPrg
Enno2f25e402023-08-23 21:27:50 +020032 if !exists('b:undo_ftplugin') || empty(b:undo_ftplugin)
33 let b:undo_ftplugin = 'setlocal keywordprg< iskeyword<'
34 else
Enno1e33cd72023-10-08 19:14:07 +020035 let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer SystemdKeywordPrg'
Enno2f25e402023-08-23 21:27:50 +020036 endif
37 endif
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020038endif