+/config

my dotfiles and nix configuration

git clone https://git.julia.blue/+/config

Julia RyanUpdate nvim and nixd0b27c7

main
3.5 KiB100 linesraw
1local cmp = require "cmp"
2local snippy = require "snippy"
3snippy.setup { hl_group = "SnippetPlaceholder" }
4-- stylua: ignore start
5vim.keymap.set({ "i", "n", "v" }, "<C-l>", function()
6    if snippy.can_jump(1) then snippy.next() else print "No more snippets" end
7end)
8vim.keymap.set({ "i", "n", "v" }, "<C-h>", function()
9    if snippy.can_jump(-1) then snippy.previous() else print "No more snippets" end
10end)
11-- stylua: ignore end
12
13require("nvim-autopairs").setup {}
14local cmp_autopairs = require "nvim-autopairs.completion.cmp"
15cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
16
17cmp.setup {
18    enabled = function()
19        return vim.api.nvim_buf_get_option(0, "buftype") ~= "prompt"
20            or require("cmp_dap").is_dap_buffer()
21    end,
22    snippet = { expand = function(args) snippy.expand_snippet(args.body) end },
23    performance = { max_view_entries = 20 },
24    sources = cmp.config.sources {
25        { name = "nvim_lsp_signature_help" },
26        { name = "nvim_lsp" },
27        { name = "snippy" },
28        { name = "buffer" },
29        { name = "path" },
30    },
31    preselect = cmp.PreselectMode.None,
32    formatting = {
33        fields = { "kind", "abbr", "menu" },
34        format = function(entry, item)
35            if vim.tbl_contains({ "path" }, entry.source.name) then
36                local icon, hl_group =
37                    require("nvim-web-devicons").get_icon(entry:get_completion_item().label)
38                if icon then
39                    item.kind = icon
40                    item.kind_hl_group = hl_group
41                    return item
42                end
43            end
44            item = require("lspkind").cmp_format {
45                mode = "symbol_text",
46                maxwidth = 30,
47                ellipsis_char = "…",
48            }(entry, item)
49            local strings = vim.split(item.kind, "%s", { trimempty = true })
50            item.kind = " " .. (strings[1] or "") .. " "
51            item.menu = "   (" .. (strings[2] or "") .. ")"
52            return item
53        end,
54    },
55    mapping = cmp.mapping.preset.insert {
56        ["<C-u>"] = cmp.mapping.scroll_docs(-8),
57        ["<C-d>"] = cmp.mapping.scroll_docs(8),
58        ["<C-e>"] = cmp.mapping.abort(),
59        ["<Esc>"] = cmp.mapping(function(fallback)
60            cmp.mapping.abort()
61            fallback()
62        end),
63        ["<C-Space>"] = cmp.mapping.complete(),
64        ["<CR>"] = cmp.mapping(function(fallback)
65            if cmp.visible() and cmp.get_active_entry() then
66                cmp.confirm { select = false }
67            else
68                fallback()
69            end
70        end, { "i" }),
71        ["<Tab>"] = cmp.mapping(function(fallback)
72            local line, col = table.unpack(vim.api.nvim_win_get_cursor(0))
73            if cmp.visible() then
74                cmp.select_next_item { behavior = cmp.SelectBehavior.Select }
75            elseif
76                col ~= 0
77                and vim.api
78                        .nvim_buf_get_lines(0, line - 1, line, true)[1]
79                        :sub(col, col)
80                        :match "%s"
81                    == nil
82            then
83                cmp.complete()
84            else
85                fallback()
86            end
87        end, { "i" }),
88        ["<S-Tab>"] = cmp.mapping(function(fallback)
89            if cmp.visible() then
90                cmp.select_prev_item { behavior = cmp.SelectBehavior.Select }
91            else
92                fallback()
93            end
94        end, { "i" }),
95    },
96}
97
98cmp.setup.filetype({ "dap-repl", "dapui_watches", "dapui_hover" }, {
99    sources = { { name = "dap" } },
100})