diff --git a/README.md b/README.md index 1444563..9a4d8fa 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,63 @@ -## Epo +## epo.nvim -a blazing fast and minimal less than 300 lines. neovim lsp auto-completion plugin. +Blazingly fast, minimal lsp auto-completion and snippet plugin for neovim. -**Need neovim nightly** +**Needs neovim nightly** +**This plugin would be much more feature-complete after [this pr](https://github.com/neovim/neovim/pull/24723) is merged** ## Usage ```lua +-- suggested completeopt +vim.opt.completeopt = "menu,menuone,noselect" + +-- default settings require('epo').setup({ - -- default value of options. + -- fuzzy match fuzzy = false, -- increase this value can aviod trigger complete when delete character. debounce = 50, -- when completion confrim auto show a signature help floating window. signature = false, - -- extend vscode format snippet json files. like rust.json/typescriptreact.json/zig.json + -- vscode style json snippet path snippet_path = nil, + -- border for lsp signature popup, :h nvim_open_win + signature_border = 'rounded' + -- lsp kind formatting, k is kind string "Field", "Struct", "Keyword" etc. + kind_format = function(k) + return k:lower():sub(1, 1) + end }) ``` -register capabilities for `vim.snippet` +You may want to pass the capabilities to your lsp ```lua -server_config = { - capabilities = vim.tbl_deep_extend( +local capabilities = vim.tbl_deep_extend( 'force', vim.lsp.protocol.make_client_capabilities(), require('epo').register_cap() ) -} ``` -## Keymap +Completion menu look dull and boring? Your colorscheme may be missing these highlights: + +``` +Pmenu +PmenuExtra +PmenuSel +PmenuKind +PmenuKindSel +PmenuExtraSel +PmenuSbar +PmenuThumb +``` + +
+Click to show some mapping presets -Super TAB and Shift-tab bind tab and shift-tab for completion and snippet -expand. +- TAB complete ```lua vim.keymap.set('i', '', function() @@ -66,7 +88,26 @@ vim.keymap.set('i', '', function() end, {expr = true}) ``` +- use `` to accept completion + +```lua +-- For using enter as completion, may conflict with some autopair plugin +vim.keymap.set("i", "", function() + if vim.fn.pumvisible() == 1 then + return "" + end + return "" +end, { expr = true, noremap = true }) + +-- nvim-autopair compatibility +vim.keymap.set("i", "", function() + if vim.fn.pumvisible() == 1 then + return "" + end + return require("nvim-autopairs").autopairs_cr() +end, { expr = true, noremap = true }) +``` -third param is fuzzy match enable. +
## License MIT diff --git a/lua/epo/init.lua b/lua/epo/init.lua index 63a24d4..d0ed101 100644 --- a/lua/epo/init.lua +++ b/lua/epo/init.lua @@ -7,7 +7,8 @@ local ns = api.nvim_create_namespace('Epo') local match_fuzzy = false local signature = false local debounce_time = 100 -local snippet_path = nil +local snippet_path, signature_border, kind_format + -- Ctrl-Y will trigger TextChangedI again -- avoid completion redisplay add a status check local disable = nil @@ -59,7 +60,7 @@ end local function lspkind(kind) local k = protocol.CompletionItemKind[kind] or 'Unknown' - return k:lower():sub(1, 1) + return kind_format(k) end local function show_info(bufnr) @@ -113,7 +114,7 @@ local function signature_help(client, bufnr, lnum) lines = { unpack(lines, 1, 3) } fbuf, fwin = util.open_floating_preview(lines, 'markdown', { close_events = {}, - border = 'rounded', + border = signature_border, }) vim.bo[fbuf].syntax = 'on' @@ -516,6 +517,10 @@ local function setup(opt) debounce_time = opt.debounce_time or 50 signature = opt.signature or false snippet_path = opt.snippet_path + signature_border = opt.signature_border or 'rounded' + kind_format = opt.kind_format or function(k) + return k:lower():sub(1, 1) + end -- Usually I just use one client for completion so just one api.nvim_create_autocmd('LspAttach', {