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