]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/coding.lua
a2e1538516cf10c5a281727e0968ebf5bba9dd56
[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 keys = function()
8 return {}
9 end,
10 },
11
12 -- auto completion
13 {
14 "hrsh7th/nvim-cmp",
15 ---@param opts cmp.ConfigSchema
16 opts = function(_, opts)
17 local has_words_before = function()
18 unpack = unpack or table.unpack
19 local line, col = unpack(vim.api.nvim_win_get_cursor(0))
20 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
21 end
22
23 local cmp = require("cmp")
24 local luasnip = require("luasnip")
25
26 opts.completion = vim.tbl_extend("force", opts.completion, {
27 completeopt = "menu,menuone,noselect",
28 })
29 --TODO: review if I want to keep any of LazyVim's mappings
30 opts.mapping = vim.tbl_extend("force", opts.mapping, {
31 ["<Tab>"] = cmp.mapping(function(fallback)
32 if cmp.visible() then
33 cmp.select_next_item()
34 elseif luasnip.expand_or_jumpable() then
35 luasnip.expand_or_jump()
36 elseif has_words_before() then
37 cmp.complete()
38 else
39 fallback()
40 end
41 end, { "i", "s" }),
42 ["<S-Tab>"] = cmp.mapping(function(fallback)
43 if cmp.visible() then
44 cmp.select_prev_item()
45 elseif luasnip.jumpable(-1) then
46 luasnip.jump(-1)
47 else
48 fallback()
49 end
50 end, { "i", "s" }),
51 })
52 end,
53 },
54
55 -- auto pairs
56 {
57 "echasnovski/mini.pairs",
58 },
59
60 -- surround
61 {
62 "echasnovski/mini.surround",
63 keys = {
64 { "S", "<cmd><C-u>lua MiniSurround.add('visual')<cr>", "x" },
65 { "yss", "ys_", remap = true },
66 },
67 opts = {
68 mappings = {
69 -- TODO: this is tpope/surround like, but should consider using vim-sandwich mappings
70 -- see: :h MiniSurround-vim-surround-config
71 add = "ys",
72 delete = "ds",
73 find = "",
74 find_left = "",
75 highlight = "",
76 replace = "cs",
77 update_n_lines = "",
78 },
79 },
80 },
81 }