]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/nvim/lua/plugins/blink-cmp.lua
+use/op(nvim): tweak config
[julm/julm-nix.git] / home-manager / profiles / nvim / lua / plugins / blink-cmp.lua
1 -- Performant, batteries-included completion plugin for Neovim.
2 -- https://github.com/Saghen/blink.cmp
3 return {
4 "blink.cmp",
5 event = "InsertEnter",
6 load = function(name)
7 vim.cmd.packadd(name)
8 vim.cmd.packadd("blink-emoji.nvim")
9 end,
10 after = function()
11 require("blink-cmp").setup({
12 -- Enables keymaps, completions and signature help when true (doesn't apply to cmdline or term)
13 --
14 -- If the function returns 'force', the default conditions for disabling the plugin will be ignored
15 -- Default conditions: (vim.bo.buftype ~= 'prompt' and vim.b.completion ~= false)
16 -- Note that the default conditions are ignored when `vim.b.completion` is explicitly set to `true`
17 --
18 -- Exceptions: vim.bo.filetype == 'dap-repl'
19 --enabled = function()
20 -- return not vim.tbl_contains({ "lua", "markdown" }, vim.bo.filetype)
21 --end,
22
23 -- Disable cmdline
24 -- cmdline = { enabled = false },
25
26 fuzzy = {
27 -- ToDo: re-enable after the fix https://github.com/Saghen/blink.cmp/issues/1743
28 --implementation = "prefer_rust_with_warning",
29 implementation = "lua",
30 sorts = {
31 "score", -- Primary sort: by fuzzy matching score
32 "sort_text", -- Secondary sort: by sortText field if scores are equal
33 "label", -- Tertiary sort: by label if still tied
34 },
35 },
36
37 completion = {
38 -- 'prefix' will fuzzy match on the text before the cursor
39 -- 'full' will fuzzy match on the text before _and_ after the cursor
40 -- example: 'foo_|_bar' will match 'foo_' for 'prefix' and 'foo__bar' for 'full'
41 keyword = { range = "prefix" },
42 trigger = {
43 --show_on_backspace = true,
44 --show_on_backspace_in_keyword = true,
45 },
46
47 -- Disable auto brackets
48 -- NOTE: some LSPs may add auto brackets themselves anyway
49 accept = { auto_brackets = { enabled = false } },
50 list = {
51 selection = {
52 preselect = true,
53 auto_insert = true,
54 },
55 },
56 -- or set via a function
57 --list = {
58 -- selection = {
59 -- preselect = function(ctx)
60 -- return vim.bo.filetype ~= "markdown"
61 -- end,
62 -- },
63 --},
64
65 menu = {
66 auto_show = true,
67
68 -- nvim-cmp style menu
69 --draw = {
70 -- columns = {
71 -- { "label", "label_description", gap = 1 },
72 -- { "kind_icon", "kind" },
73 -- },
74 --},
75 },
76
77 -- Show documentation when selecting a completion item
78 documentation = { auto_show = true, auto_show_delay_ms = 2000 },
79
80 -- Whether to display a preview of the selected item on the current line
81 ghost_text = { enabled = true },
82 },
83 keymap = {
84 -- set to 'none' to disable the 'default' preset
85 preset = "none",
86
87 ["<C-space>"] = { "show", "show_documentation", "hide_documentation" },
88 ["<C-e>"] = { "hide", "fallback" },
89 --["<Tab>"] = { "select_next" },
90 --["<S-Tab>"] = { "select_prev" },
91 --["<Tab>"] = { "show_and_insert_or_accept_single" },
92 ["<Tab>"] = { "accept", "fallback" },
93
94 --["<Tab>"] = { "snippet_forward", "fallback" },
95 --["<S-Tab>"] = { "snippet_backward", "fallback" },
96
97 ["<Up>"] = { "select_prev", "fallback" },
98 ["<Down>"] = { "select_next", "fallback" },
99 ["<C-i>"] = { "select_prev", "fallback_to_mappings" },
100 ["<C-k>"] = { "select_next", "fallback_to_mappings" },
101
102 ["<C-j>"] = { "scroll_documentation_up", "fallback" },
103 ["<C-l>"] = { "scroll_documentation_down", "fallback" },
104
105 ["<C-n>"] = { "show_signature", "hide_signature", "fallback" },
106 },
107
108 sources = {
109 -- Remove 'buffer' if you don't want text completions,
110 -- by default it's only enabled when LSP returns no items
111 default = { "path", "lsp", "snippets", "buffer", "emoji" },
112 providers = {
113
114 -- Always show the buffer source even when the LSP provides some completion
115 lsp = { fallbacks = {} },
116 buffer = {
117 score_offset = -3,
118 opts = {
119 get_bufnrs = function()
120 return vim.api.nvim_list_bufs()
121 end,
122 -- from all "normal" buffers
123 -- get_bufnrs = function()
124 -- return vim.tbl_filter(function(bufnr)
125 -- return vim.bo[bufnr].buftype == ""
126 -- end, vim.api.nvim_list_bufs())
127 -- end,
128 -- buffers when searching with `/` or `?`
129 get_search_bufnrs = function()
130 return { vim.api.nvim_get_current_buf() }
131 end,
132 retention_order = { "focused", "visible", "recency", "largest" },
133 use_cache = true,
134 enable_in_ex_commands = false,
135 },
136 },
137 emoji = {
138 module = "blink-emoji",
139 name = "Emoji",
140 score_offset = 15, -- Tune by preference
141 opts = {
142 insert = true, -- Insert emoji (default) or complete its name
143 ---@type string|table|fun():table
144 trigger = function()
145 return { ":" }
146 end,
147 },
148 should_show_items = function()
149 return vim.tbl_contains(
150 -- Enable emoji completion only for git commits and markdown.
151 -- By default, enabled for all file-types.
152 { "gitcommit", "markdown", "jj" },
153 vim.o.filetype
154 )
155 end,
156 },
157 path = {
158 opts = {
159 -- get_cwd = function(_)
160 -- return vim.fn.getcwd()
161 -- end,
162 },
163 },
164 },
165 },
166
167 -- Use a preset for snippets, check the snippets documentation for more information
168 snippets = { preset = "default" }, -- | "luasnip" | "mini_snippets" | "vsnip"
169
170 -- Experimental signature help support
171 signature = { enabled = true },
172 })
173 end,
174 }