]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/coding.lua
nvim/coding: switch to comments.nvim
[dotfiles.git] / nvim / lua / plugins / coding.lua
1 ---@type LazyPluginSpec
2 return {
3 -- snippets
4 {
5 "L3MON4D3/LuaSnip",
6 -- disable luasnip bindings for <tab> and <s-tab>
7 dependencies = {
8 {
9 "honza/vim-snippets",
10 config = function()
11 require("luasnip.loaders.from_snipmate").lazy_load()
12 end,
13 },
14 },
15 keys = function()
16 return {}
17 end,
18 },
19
20 -- auto completion
21 {
22 "hrsh7th/nvim-cmp",
23 ---@param opts cmp.ConfigSchema
24 opts = function(_, opts)
25 local has_words_before = function()
26 unpack = unpack or table.unpack
27 local line, col = unpack(vim.api.nvim_win_get_cursor(0))
28 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
29 end
30
31 local cmp = require("cmp")
32 local luasnip = require("luasnip")
33
34 opts.completion = vim.tbl_extend("force", opts.completion, {
35 completeopt = "menu,menuone,noselect",
36 })
37 --TODO: review if I want to keep any of LazyVim's mappings
38 opts.mapping = vim.tbl_extend("force", opts.mapping, {
39 ["<Tab>"] = cmp.mapping(function(fallback)
40 if cmp.visible() then
41 cmp.select_next_item()
42 elseif luasnip.expand_or_jumpable() then
43 luasnip.expand_or_jump()
44 elseif has_words_before() then
45 cmp.complete()
46 else
47 fallback()
48 end
49 end, { "i", "s" }),
50 ["<S-Tab>"] = cmp.mapping(function(fallback)
51 if cmp.visible() then
52 cmp.select_prev_item()
53 elseif luasnip.jumpable(-1) then
54 luasnip.jump(-1)
55 else
56 fallback()
57 end
58 end, { "i", "s" }),
59 })
60 end,
61 },
62
63 -- auto pairs
64 {
65 "echasnovski/mini.pairs",
66 },
67
68 -- surround
69 {
70 "echasnovski/mini.surround",
71 keys = {
72 { "S", "<cmd><C-u>lua MiniSurround.add('visual')<cr>", "x" },
73 { "yss", "ys_", remap = true },
74 },
75 opts = {
76 mappings = {
77 -- TODO: this is tpope/surround like, but should consider using vim-sandwich mappings
78 -- see: :h MiniSurround-vim-surround-config
79 add = "ys",
80 delete = "ds",
81 find = "",
82 find_left = "",
83 highlight = "",
84 replace = "cs",
85 update_n_lines = "",
86 },
87 },
88 },
89 -- comments
90 {
91 "numToStr/Comment.nvim",
92 opts = {
93 toggler = {
94 line = "gcc",
95 block = "gbb",
96 },
97 mappings = {
98 basic = true,
99 extra = true,
100 },
101 },
102 },
103 { "JoosepAlviste/nvim-ts-context-commentstring", enabled = false },
104 { "echasnovski/mini.comment", enabled = false },
105 }