systemd.vim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. " Vim filetype plugin file
  2. " Language: systemd.unit(5)
  3. " Keyword Lookup Support: Enno Nagel <enno.nagel+vim@gmail.com>
  4. if !exists('b:did_ftplugin')
  5. " Looks a lot like dosini files.
  6. runtime! ftplugin/dosini.vim
  7. endif
  8. if !has('unix')
  9. finish
  10. endif
  11. if !has('gui_running')
  12. command! -buffer -nargs=1 Sman silent exe '!' . KeywordLookup_systemd(<q-args>) | redraw!
  13. elseif has('terminal')
  14. command! -buffer -nargs=1 Sman silent exe 'term ' . KeywordLookup_systemd(<q-args>)
  15. else
  16. finish
  17. endif
  18. 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
  28. endif
  29. setlocal iskeyword+=-
  30. setlocal keywordprg=:Sman
  31. if !exists('b:undo_ftplugin') || empty(b:undo_ftplugin)
  32. let b:undo_ftplugin = 'setlocal keywordprg< iskeyword<'
  33. else
  34. let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword<'
  35. endif