]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/coding.lua
263071dbc127fb61a2fd31b7d178df6ffbe2a95c
[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 opts = function(_, opts)
16 local has_words_before = function()
17 unpack = unpack or table.unpack
18 local line, col = unpack(vim.api.nvim_win_get_cursor(0))
19 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
20 end
21
22 local cmp = require("cmp")
23 local luasnip = require("luasnip")
24
25 opts.completion = vim.tbl_extend("force", opts.completion, {
26 completeopt = "menu,menuone,noselect",
27 })
28 --TODO: review if I want to keep any of LazyVim's mappings
29 opts.mapping = vim.tbl_extend("force", opts.mapping, {
30 ["<Tab>"] = cmp.mapping(function(fallback)
31 if cmp.visible() then
32 cmp.select_next_item()
33 elseif luasnip.expand_or_jumpable() then
34 luasnip.expand_or_jump()
35 elseif has_words_before() then
36 cmp.complete()
37 else
38 fallback()
39 end
40 end, { "i", "s" }),
41 ["<S-Tab>"] = cmp.mapping(function(fallback)
42 if cmp.visible() then
43 cmp.select_prev_item()
44 elseif luasnip.jumpable(-1) then
45 luasnip.jump(-1)
46 else
47 fallback()
48 end
49 end, { "i", "s" }),
50 })
51 end,
52 },
53 }