blob: 8bcacdd381e8301209cb71bf555051fac310ee28 [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
6if !exists('b:did_ftplugin')
7 " Looks a lot like dosini files.
8 runtime! ftplugin/dosini.vim
9endif
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020010
Enno2f25e402023-08-23 21:27:50 +020011if has('unix') && executable('less')
12 if !has('gui_running')
Enno1e33cd72023-10-08 19:14:07 +020013 command -buffer -nargs=1 SystemdKeywordPrg silent exe '!' . KeywordLookup_systemd(<q-args>) | redraw!
Enno2f25e402023-08-23 21:27:50 +020014 elseif has('terminal')
Enno1e33cd72023-10-08 19:14:07 +020015 command -buffer -nargs=1 SystemdKeywordPrg silent exe 'term ' . KeywordLookup_systemd(<q-args>)
Enno2f25e402023-08-23 21:27:50 +020016 endif
Enno1e33cd72023-10-08 19:14:07 +020017 if exists(':SystemdKeywordPrg') == 2
Enno2f25e402023-08-23 21:27:50 +020018 if !exists('*KeywordLookup_systemd')
19 function KeywordLookup_systemd(keyword) abort
20 let matches = matchlist(getline(search('\v^\s*\[\s*.+\s*\]\s*$', 'nbWz')), '\v^\s*\[\s*(\k+).*\]\s*$')
21 if len(matches) > 1
22 let section = matches[1]
23 return 'LESS= MANPAGER="less --pattern=''(^|,)\s+' . a:keyword . '=$'' --hilite-search" man ' . 'systemd.' . section
24 else
25 return 'LESS= MANPAGER="less --pattern=''(^|,)\s+' . a:keyword . '=$'' --hilite-search" man ' . 'systemd'
26 endif
27 endfunction
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020028 endif
Enno2f25e402023-08-23 21:27:50 +020029 setlocal iskeyword+=-
Enno1e33cd72023-10-08 19:14:07 +020030 setlocal keywordprg=:SystemdKeywordPrg
Enno2f25e402023-08-23 21:27:50 +020031 if !exists('b:undo_ftplugin') || empty(b:undo_ftplugin)
32 let b:undo_ftplugin = 'setlocal keywordprg< iskeyword<'
33 else
Enno1e33cd72023-10-08 19:14:07 +020034 let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer SystemdKeywordPrg'
Enno2f25e402023-08-23 21:27:50 +020035 endif
36 endif
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020037endif