]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/coding.lua
7bf442fe954d7956c4062b013dae9fea1216a151
[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 opts = {
19 store_selection_keys = "<Tab>",
20 },
21 },
22
23 -- auto completion
24 {
25 "hrsh7th/nvim-cmp",
26 ---@param opts cmp.ConfigSchema
27 opts = function(_, opts)
28 local has_words_before = function()
29 unpack = unpack or table.unpack
30 local line, col = unpack(vim.api.nvim_win_get_cursor(0))
31 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
32 end
33
34 local cmp = require("cmp")
35 local luasnip = require("luasnip")
36
37 local upstream_format = opts.formatting.format
38 opts.formatting.format = function(entry, vim_item)
39 vim_item = upstream_format(entry, vim_item)
40 local menu = {
41 nvim_lsp = "[lsp]",
42 luasnip = "[snip]",
43 buffer = "[buf]",
44 path = "[path]",
45 }
46 vim_item.menu = menu[entry.source.name]
47 return vim_item
48 end
49
50 opts.completion = vim.tbl_extend("force", opts.completion, {
51 completeopt = "menu,menuone,noselect",
52 })
53 -- TODO: review if I want to keep any of LazyVim's mappings
54 opts.mapping = cmp.mapping.preset.insert({
55 -- lazyvims
56 ["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
57 ["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
58 ["<C-b>"] = cmp.mapping.scroll_docs(-4),
59 ["<C-f>"] = cmp.mapping.scroll_docs(4),
60 ["<C-e>"] = cmp.mapping.abort(),
61 ["<C-Space>"] = cmp.mapping.complete(),
62 -- mine
63 ["<Tab>"] = cmp.mapping(function(fallback)
64 if cmp.visible() then
65 cmp.select_next_item()
66 elseif luasnip.expand_or_jumpable() then
67 luasnip.expand_or_jump()
68 elseif has_words_before() then
69 cmp.complete()
70 else
71 fallback()
72 end
73 end, { "i", "s" }),
74 ["<S-Tab>"] = cmp.mapping(function(fallback)
75 if cmp.visible() then
76 cmp.select_prev_item()
77 elseif luasnip.jumpable(-1) then
78 luasnip.jump(-1)
79 else
80 fallback()
81 end
82 end, { "i", "s" }),
83 })
84 end,
85 },
86
87 -- auto pairs
88 {
89 "echasnovski/mini.pairs",
90 },
91
92 -- surround
93 {
94 "echasnovski/mini.surround",
95 keys = {
96 { "S", "<cmd><C-u>lua MiniSurround.add('visual')<cr>", "x" },
97 { "yss", "ys_", remap = true },
98 },
99 opts = {
100 mappings = {
101 -- TODO: this is tpope/surround like, but should consider using vim-sandwich mappings
102 -- see: :h MiniSurround-vim-surround-config
103 add = "ys",
104 delete = "ds",
105 find = "",
106 find_left = "",
107 highlight = "",
108 replace = "cs",
109 update_n_lines = "",
110 },
111 },
112 },
113 -- comments
114 {
115 "numToStr/Comment.nvim",
116 opts = {
117 toggler = {
118 line = "gcc",
119 block = "gbb",
120 },
121 mappings = {
122 basic = true,
123 extra = true,
124 },
125 },
126 },
127 { "JoosepAlviste/nvim-ts-context-commentstring", enabled = false },
128 { "echasnovski/mini.comment", enabled = false },
129 }