comment.lua 2.2 KB

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