systemd.vim 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. " Vim filetype plugin file
  2. " Language: systemd.unit(5)
  3. " Keyword Lookup Support: Enno Nagel <enno.nagel+vim@gmail.com>
  4. " Latest Revision: 2024-10-02 (small fixes to &keywordprg)
  5. if exists("b:did_ftplugin")
  6. finish
  7. endif
  8. " Looks a lot like dosini files.
  9. runtime! ftplugin/dosini.vim
  10. if has('unix') && executable('less') && exists(':terminal') == 2
  11. command! -buffer -nargs=1 SystemdKeywordPrg silent exe 'term ++close ' KeywordLookup_systemd(<q-args>)
  12. silent! function KeywordLookup_systemd(keyword) abort
  13. let matches = matchlist(getline(search('\v^\s*\[\s*.+\s*\]\s*$', 'nbWz')), '\v^\s*\[\s*(\k+).*\]\s*$')
  14. if len(matches) > 1
  15. let section = matches[1]
  16. return 'env LESS= MANPAGER="less --pattern=''(^|,)\\s+' . a:keyword . '=$'' --hilite-search" man ' . 'systemd.' . section
  17. else
  18. return 'env LESS= MANPAGER="less --pattern=''(^|,)\\s+' . a:keyword . '=$'' --hilite-search" man ' . 'systemd'
  19. endif
  20. endfunction
  21. setlocal iskeyword+=-
  22. setlocal keywordprg=:SystemdKeywordPrg
  23. if !exists('b:undo_ftplugin') || empty(b:undo_ftplugin)
  24. let b:undo_ftplugin = 'setlocal keywordprg< iskeyword< | sil! delc -buffer SystemdKeywordPrg'
  25. else
  26. let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer SystemdKeywordPrg'
  27. endif
  28. endif