]> git.rmz.io Git - dotfiles.git/blobdiff - nvim/lua/plugins/coding.lua
nvim: get cpp lang from lazyvim
[dotfiles.git] / nvim / lua / plugins / coding.lua
index 6a6ded82b3ce2691fcbcbe21ce48da7c6aa092db..324dc4ea1b71758902b3c074bcc3ab5f0e942658 100644 (file)
@@ -4,9 +4,21 @@ return {
   {
     "L3MON4D3/LuaSnip",
     -- disable luasnip bindings for <tab> and <s-tab>
+    dependencies = {
+      {
+        "honza/vim-snippets",
+        config = function()
+          require("luasnip.loaders.from_snipmate").lazy_load()
+          require("luasnip.loaders.from_lua").load({ paths = vim.fn.stdpath("config") .. "/lua/snippets" })
+        end,
+      },
+    },
     keys = function()
       return {}
     end,
+    opts = {
+      store_selection_keys = "<Tab>",
+    },
   },
 
   -- auto completion
@@ -23,11 +35,32 @@ return {
       local cmp = require("cmp")
       local luasnip = require("luasnip")
 
+      local upstream_format = opts.formatting.format
+      opts.formatting.format = function(entry, vim_item)
+        vim_item = upstream_format(entry, vim_item)
+        local menu = {
+          nvim_lsp = "[lsp]",
+          luasnip = "[snip]",
+          buffer = "[buf]",
+          path = "[path]",
+        }
+        vim_item.menu = menu[entry.source.name]
+        return vim_item
+      end
+
       opts.completion = vim.tbl_extend("force", opts.completion, {
         completeopt = "menu,menuone,noselect",
       })
-      --TODO: review if I want to keep any of LazyVim's mappings
-      opts.mapping = vim.tbl_extend("force", opts.mapping, {
+      -- TODO: review if I want to keep any of LazyVim's mappings
+      opts.mapping = cmp.mapping.preset.insert({
+        -- lazyvims
+        ["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
+        ["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
+        ["<C-b>"] = cmp.mapping.scroll_docs(-4),
+        ["<C-f>"] = cmp.mapping.scroll_docs(4),
+        ["<C-e>"] = cmp.mapping.abort(),
+        ["<C-Space>"] = cmp.mapping.complete(),
+        -- mine
         ["<Tab>"] = cmp.mapping(function(fallback)
           if cmp.visible() then
             cmp.select_next_item()
@@ -56,4 +89,54 @@ return {
   {
     "echasnovski/mini.pairs",
   },
+
+  -- surround
+  {
+    "echasnovski/mini.surround",
+    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
+        -- see: :h MiniSurround-vim-surround-config
+        add = "ys",
+        delete = "ds",
+        find = "",
+        find_left = "",
+        highlight = "",
+        replace = "cs",
+        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
+  {
+    "numToStr/Comment.nvim",
+    opts = {
+      toggler = {
+        line = "gcc",
+        block = "gbb",
+      },
+      mappings = {
+        basic = true,
+        extra = true,
+      },
+    },
+  },
+  { "JoosepAlviste/nvim-ts-context-commentstring", enabled = false },
+  { "echasnovski/mini.comment", enabled = false },
 }