comment.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. local M = {}
  2. function M.config()
  3. local pre_hook
  4. local loaded, ts_comment = pcall(require, "ts_context_commentstring.integrations.comment_nvim")
  5. if loaded and ts_comment then
  6. pre_hook = ts_comment.create_pre_hook()
  7. end
  8. lvim.builtin.comment = {
  9. active = true,
  10. on_config_done = nil,
  11. ---Add a space b/w comment and the line
  12. ---@type boolean
  13. padding = true,
  14. ---Whether cursor should stay at the
  15. ---same position. Only works in NORMAL
  16. ---mode mappings
  17. sticky = true,
  18. ---Lines to be ignored while comment/uncomment.
  19. ---Could be a regex string or a function that returns a regex string.
  20. ---Example: Use '^$' to ignore empty lines
  21. ---@type string|function
  22. ignore = "^$",
  23. ---Whether to create basic (operator-pending) and extra mappings for NORMAL/VISUAL mode
  24. ---@type table
  25. mappings = {
  26. ---operator-pending mapping
  27. ---Includes `gcc`, `gcb`, `gc[count]{motion}` and `gb[count]{motion}`
  28. basic = true,
  29. ---Extra mapping
  30. ---Includes `gco`, `gcO`, `gcA`
  31. extra = true,
  32. },
  33. ---LHS of line and block comment toggle mapping in NORMAL/VISUAL mode
  34. ---@type table
  35. toggler = {
  36. ---line-comment toggle
  37. line = "gcc",
  38. ---block-comment toggle
  39. block = "gbc",
  40. },
  41. ---LHS of line and block comment operator-mode mapping in NORMAL/VISUAL mode
  42. ---@type table
  43. opleader = {
  44. ---line-comment opfunc mapping
  45. line = "gc",
  46. ---block-comment opfunc mapping
  47. block = "gb",
  48. },
  49. ---LHS of extra mappings
  50. ---@type table
  51. extra = {
  52. ---Add comment on the line above
  53. above = "gcO",
  54. ---Add comment on the line below
  55. below = "gco",
  56. ---Add comment at the end of line
  57. eol = "gcA",
  58. },
  59. ---Pre-hook, called before commenting the line
  60. ---@type function|nil
  61. pre_hook = pre_hook,
  62. ---Post-hook, called after commenting is done
  63. ---@type function|nil
  64. post_hook = nil,
  65. }
  66. end
  67. function M.setup()
  68. local nvim_comment = require "Comment"
  69. nvim_comment.setup(lvim.builtin.comment)
  70. if lvim.builtin.comment.on_config_done then
  71. lvim.builtin.comment.on_config_done(nvim_comment)
  72. end
  73. end
  74. return M