1
0

editing.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. local MiniAi = require('mini.ai')
  2. local MiniAlign = require('mini.align')
  3. local MiniComment = require('mini.comment')
  4. local MiniOperators = require('mini.operators')
  5. local MiniPairs = require('mini.pairs')
  6. local MiniSurround = require('mini.surround')
  7. -- comment actions
  8. MiniComment.setup()
  9. -- keymap: overrides default vim gc / gcc
  10. -- surround actions
  11. MiniSurround.setup({
  12. custom_surroundings = {
  13. -- js template string
  14. ['$'] = {
  15. output = {
  16. left = '`${',
  17. right = '}`',
  18. },
  19. },
  20. },
  21. })
  22. -- keymap:
  23. -- sa (surround add)
  24. -- sr (surround replace)
  25. -- sd (surround delete)
  26. local spec_treesitter = require('mini.ai').gen_spec.treesitter
  27. MiniAi.setup({
  28. -- only consider the current location
  29. search_method = 'cover',
  30. custom_textobjects = {
  31. ['.'] = spec_treesitter({
  32. a = '@call.outer',
  33. i = '@call.inner',
  34. }),
  35. [','] = spec_treesitter({
  36. a = '@parameter.outer',
  37. i = '@parameter.inner',
  38. }),
  39. },
  40. });
  41. -- align actions
  42. MiniAlign.setup()
  43. -- keymap: ga / gA
  44. -- Treesitter-aware split/join
  45. require('treesj').setup({
  46. use_default_keymaps = false,
  47. })
  48. vim.keymap.set('n', '<Leader>s', '<cmd>TSJSplit<CR>')
  49. vim.keymap.set('n', '<Leader>j', '<cmd>TSJJoin<CR>')
  50. -- autopair brackets
  51. MiniPairs.setup({
  52. mappings = {
  53. -- default config includes (, [ and {
  54. -- autopair <> if preceded by a character, otherwise it might be a regular
  55. -- comparison operation
  56. ['<'] = { action = 'open', pair = '<>', neigh_pattern = '%w.' },
  57. ['>'] = { action = 'close', pair = '<>' },
  58. },
  59. })
  60. -- extra operators
  61. MiniOperators.setup({
  62. -- disable evaluate mapping
  63. evaluate = { prefix = '' },
  64. -- custom mapping defined later
  65. replace = { prefix = '' },
  66. -- other mappings
  67. -- gm - multiply
  68. -- gs - sort
  69. -- gx - exchange
  70. })
  71. MiniOperators.make_mappings('replace', {
  72. textobject = 'cp',
  73. line = 'cpp',
  74. -- overrides default p mapping
  75. selection = 'p',
  76. })
  77. local function toggle_end_char(char)
  78. local cursor = vim.api.nvim_win_get_cursor(0)
  79. local row = cursor[1] - 1
  80. local end_char = vim.api.nvim_buf_get_text(0, row, -2, row, -1, {})[1]
  81. if end_char == char then
  82. vim.api.nvim_buf_set_text(0, row, -2, row, -1, {})
  83. else
  84. vim.api.nvim_buf_set_text(0, row, -1, row, -1, { char })
  85. end
  86. end
  87. -- add ,/; to end of line
  88. vim.keymap.set('i', '<C-,>', function() toggle_end_char(',') end)
  89. vim.keymap.set('i', '<C-;>', function() toggle_end_char(';') end)