man.lua 807 B

123456789101112131415161718192021222324252627282930313233343536
  1. if vim.g.loaded_man ~= nil then
  2. return
  3. end
  4. vim.g.loaded_man = true
  5. vim.api.nvim_create_user_command('Man', function(params)
  6. local man = require('man')
  7. if params.bang then
  8. man.init_pager()
  9. else
  10. local ok, err = pcall(man.open_page, params.count, params.smods, params.fargs)
  11. if not ok then
  12. vim.notify(man.errormsg or err, vim.log.levels.ERROR)
  13. end
  14. end
  15. end, {
  16. bang = true,
  17. bar = true,
  18. range = true,
  19. addr = 'other',
  20. nargs = '*',
  21. complete = function(...)
  22. return require('man').man_complete(...)
  23. end,
  24. })
  25. local augroup = vim.api.nvim_create_augroup('man', {})
  26. vim.api.nvim_create_autocmd('BufReadCmd', {
  27. group = augroup,
  28. pattern = 'man://*',
  29. callback = function(params)
  30. require('man').read_page(vim.fn.matchstr(params.match, 'man://\\zs.*'))
  31. end,
  32. })