nvim 基于buffer的文本补全

注意
本文最后更新于 2024-06-21,文中内容可能已过时。

nvim 可以通过插件lsp实现基于编程语法的自动补全。而对于一般的文本,lsp 就无助于事了。这时候我们需要一个基于文本分析的自动补全功能。这个可以通过 echasnovski/mini.nvim 来实现

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
return {
    "echasnovski/mini.nvim",
    enabled = true,
    event = "VeryLazy",
    config = function()
        require("mini.completion").setup {
            -- Delay (debounce type, in ms) between certain Neovim event and action.
            -- This can be used to (virtually) disable certain automatic actions by
            -- setting very high delay time (like 10^7).
            delay = { completion = 100, info = 100, signature = 50 },

            -- Configuration for action windows:
            -- - `height` and `width` are maximum dimensions.
            -- - `border` defines border (as in `nvim_open_win()`).
            window = {
                info = { height = 25, width = 80, border = 'none' },
                signature = { height = 25, width = 80, border = 'none' },
            },

            -- Way of how module does LSP completion
            lsp_completion = {
                -- `source_func` should be one of 'completefunc' or 'omnifunc'.
                source_func = 'completefunc',

                -- `auto_setup` should be boolean indicating if LSP completion is set up
                -- on every `BufEnter` event.
                auto_setup = true,

                -- `process_items` should be a function which takes LSP
                -- 'textDocument/completion' response items and word to complete. Its
                -- output should be a table of the same nature as input items. The most
                -- common use-cases are custom filtering and sorting. You can use
                -- default `process_items` as `MiniCompletion.default_process_items()`.
                -- process_items = --<function: filters out snippets; sorts by LSP specs>,
            },

            -- Fallback action. It will always be run in Insert mode. To use Neovim's
            -- built-in completion (see `:h ins-completion`), supply its mapping as
            -- string. Example: to use 'whole lines' completion, supply '<C-x><C-l>'.
            -- fallback_action = --<function: like `<C-n>` completion>,

                -- Module mappings. Use `''` (empty string) to disable one. Some of them
                -- might conflict with system mappings.
                -- mappings = {
                --     force_twostep = '<C-Space>', -- Force two-step completion
                --     force_fallback = '<A-Space>', -- Force fallback completion
                -- },

            -- Whether to set Vim's settings for better experience (modifies
            -- `shortmess` and `completeopt`)
            set_vim_settings = true,
        }
    end
}
william 支付宝支付宝
william 微信微信
0%