]> git.rmz.io Git - dotfiles.git/commitdiff
nvim: make MiniSurround behave more like tpope/surround
authorSamir Benmendil <me@rmz.io>
Sun, 17 Dec 2023 17:28:40 +0000 (17:28 +0000)
committerSamir Benmendil <me@rmz.io>
Sun, 17 Dec 2023 17:28:40 +0000 (17:28 +0000)
nvim/lua/plugins/coding.lua

index 7bf442fe954d7956c4062b013dae9fea1216a151..bda4a988e246cff23a775d2e20e5f98fd400ffc2 100644 (file)
@@ -92,10 +92,16 @@ return {
   -- surround
   {
     "echasnovski/mini.surround",
-    keys = {
-      { "S", "<cmd><C-u>lua MiniSurround.add('visual')<cr>", "x" },
-      { "yss", "ys_", remap = true },
-    },
+    keys = function()
+      -- HACK: use function to disable merging with LazyVim's keys definition
+      return {
+        { "ys", desc = "Add surrounding", "n" },
+        { "S", desc = "Add surrounding", "x" },
+        { "ds", desc = "Delete surrounding" },
+        { "cs", desc = "Change surrounding" },
+        { "yss", "ys_", remap = true },
+      }
+    end,
     opts = {
       mappings = {
         -- TODO: this is tpope/surround like, but should consider using vim-sandwich mappings
@@ -109,6 +115,12 @@ return {
         update_n_lines = "",
       },
     },
+    config = function(_, opts)
+      require("mini.surround").setup(opts)
+      -- remap visual
+      vim.keymap.del("x", "ys", { silent = true })
+      vim.keymap.set("x", "S", [[:<C-u>lua MiniSurround.add('visual')<CR>]], { silent = true })
+    end,
   },
   -- comments
   {