From dfd2dda8d08bc4a3e15c5b30af856bd91890b4fc Mon Sep 17 00:00:00 2001 From: yannickreiss Date: Mon, 4 Sep 2023 15:26:51 +0200 Subject: [PATCH] Major refactor of code completion, now very much nicer --- init.lua | 12 +-- lua/code-completion.lua | 160 +++++++++++++++++++++------------------- lua/plugins.lua | 9 ++- viml/legacyconf.vim | 2 +- 4 files changed, 92 insertions(+), 91 deletions(-) diff --git a/init.lua b/init.lua index 97486d8..badf5c4 100644 --- a/init.lua +++ b/init.lua @@ -21,7 +21,7 @@ vim.opt.guifont = "DroidSansMono Nerd Font 11" -- set colorscheme vim.opt.termguicolors = true vim.cmd([[ -colorscheme slate +colorscheme tokyonight-night ]]) -- vim.cmd('source ~/.config/nvim/viml/plugins.vim') @@ -162,15 +162,6 @@ require("mason-lspconfig").setup_handlers({ end, }) -local wilder = require("wilder") -wilder.setup({ - modes = { ":", "/", "?" }, - next_key = "", - previous_key = "", - accept_key = "", - reject_key = "", -}) - require("code-completion") -- neovide configuration @@ -180,4 +171,3 @@ if vim.g.neovide then end vim.cmd("source ~/.config/nvim/viml/legacyconf.vim") -vim.cmd("source ~/.config/nvim/viml/macros.vim") diff --git a/lua/code-completion.lua b/lua/code-completion.lua index 3ad8457..be7505e 100644 --- a/lua/code-completion.lua +++ b/lua/code-completion.lua @@ -2,93 +2,101 @@ -- noinsert: only insert text when selection confirmed -- noselect: force to select from suggestion -- preview: show more details -vim.opt.completeopt = {'menuone', 'noselect', 'noinsert', 'preview'} +vim.opt.completeopt = { "menu", "menuone" } -- shortmess is used to reduce verbocity -- vim.opt.shortmess = vim.opt.shortmess + { c = true } +local cmp = require("cmp") +cmp.setup({ + -- configuration + snippet = { + expand = function(args) + vim.fn["UltiSnips#Anon"](args.body) + end, + }, -local cmp = require'cmp' -cmp.setup( { - -- configuration - snippet = { - expand = function(args) - vim.fn["UltiSnips#Anon"](args.body) - end, - }, - -- mapping - mapping = { - -- Shift+TAB to go to the Previous Suggested item - [''] = cmp.mapping.select_prev_item(), - -- Tab to go to the next suggestion - [''] = cmp.mapping.select_next_item(), - -- CTRL+SHIFT+f to scroll backwards in description - [''] = cmp.mapping.scroll_docs(-4), - -- CTRL+F to scroll forwards in the description - [''] = cmp.mapping.scroll_docs(4), - -- CTRL+SPACE to bring up completion at current Cursor location - [''] = cmp.mapping.complete(), - -- CTRL+e to exit suggestion and close it - [''] = cmp.mapping.close(), - -- CR (enter or return) to CONFIRM the currently selection suggestion - -- We set the ConfirmBehavior to insert the Selected suggestion - [''] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }) - }, + -- Add borders to the windows + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + + -- mapping + mapping = cmp.mapping.preset.insert({ + -- Shift+TAB to go to the Previous Suggested item + [""] = cmp.mapping.select_prev_item(), + -- Tab to go to the next suggestion + [""] = cmp.mapping.select_next_item(), + -- CTRL+SHIFT+f to scroll backwards in description + [""] = cmp.mapping.scroll_docs(-4), + -- CTRL+F to scroll forwards in the description + [""] = cmp.mapping.scroll_docs(4), + -- CTRL+SPACE to bring up completion at current Cursor location + [""] = cmp.mapping.complete(), + -- CTRL+e to exit suggestion and close it + [""] = cmp.mapping.close(), -- TODO: Search better option + -- CR (enter or return) to CONFIRM the currently selection suggestion + -- We set the ConfirmBehavior to insert the Selected suggestion + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }), + }), -- installed sources for code suggestion - sources = { - { name = 'path' }, - { name = 'nvim_lsp', keyword_length = 3 }, - { name = 'nvim_lsp_signature_help'}, - { name = 'nvim_lua', keyword_length = 2}, - { name = 'buffer', keyword_length = 2 }, - { name = 'ultisnips', keyword_length = 2 }, - { name = 'calc' }, - { name = "lua-latex-symbols", option = { cache = true } } - }, + sources = cmp.config.sources({ + { name = "path" }, + { name = "nvim_lsp", keyword_length = 1 }, + { name = "nvim_lsp_signature_help" }, + { name = "nvim_lua", keyword_length = 2 }, + { name = "buffer", keyword_length = 4 }, + { name = "ultisnips", keyword_length = 1 }, + { name = "calc" }, + { name = "lua-latex-symbols", option = { cache = true } }, + }), - -- Add borders to the windows - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - -- add formating of the different sources - formatting = { - fields = {'menu', 'abbr', 'kind'}, - format = function(entry, item) - local menu_icon ={ - nvim_lsp = 'λ', - ultisnips = '⋗', - buffer = 'b', - path = 'p', - calc = 'Σ', - lualatexsymbols = 'L' - } - item.menu = menu_icon[entry.source.name] - return item - end, - } -} ) + -- add formatting of the different sources + formatting = { + fields = { "menu", "abbr", "kind" }, + format = function(entry, item) + local menu_icon = { + nvim_lsp = "λ", + ultisnips = "⋗", + buffer = "b", + path = "p", + calc = "Σ", + lualatexsymbols = "L", + } + item.menu = menu_icon[entry.source.name] + return item + end, + }, +}) -- Set configuration for specific filetype. -cmp.setup.filetype('gitcommit', { - sources = cmp.config.sources({ - { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. - }, { - { name = 'buffer' }, - }) +cmp.setup.filetype("gitcommit", { + sources = cmp.config.sources({ + { name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it. + }, { + { name = "buffer" }, + }), }) - +-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline({ "/", "?" }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, + }, +}) -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) +cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + { name = "cmdline_history", keyword_length = 15 }, + }, { + { name = "cmdline" }, + }), }) diff --git a/lua/plugins.lua b/lua/plugins.lua index 94f176b..eef0dc0 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,12 +1,13 @@ return require("packer").startup(function(use) -- Configurations will go here soon use("wbthomason/packer.nvim") - -- use 'dense-analysis/ale' use("preservim/nerdtree") use("Xuyuanp/nerdtree-git-plugin") use("tpope/vim-surround") use("SirVer/ultisnips") + use("powerline/powerline") use("vim-airline/vim-airline") + use("vim-airline/vim-airline-themes") use({ "nvim-treesitter/nvim-treesitter", run = function() @@ -14,7 +15,6 @@ return require("packer").startup(function(use) ts_update() end, }) - use({ "gelguy/wilder.nvim" }) use({ "junegunn/fzf", run = ":call fzf#install()" }) use("junegunn/fzf.vim") use("williamboman/mason.nvim") @@ -33,6 +33,8 @@ return require("packer").startup(function(use) use("hrsh7th/cmp-path") use("hrsh7th/cmp-buffer") use("hrsh7th/cmp-calc") + use("hrsh7th/cmp-cmdline") + use("dmitmel/cmp-cmdline-history") use("amarakon/nvim-cmp-lua-latex-symbols") use("prabirshrestha/async.vim") use("prabirshrestha/vim-lsp") @@ -43,5 +45,6 @@ return require("packer").startup(function(use) use("quangnguyen30192/cmp-nvim-ultisnips") use("ryanoasis/vim-devicons") use("mhartington/formatter.nvim") - use("tzachar/highlight-undo.nvim") + use("tzachar/highlight-undo.nvim") + use("folke/tokyonight.nvim") end) diff --git a/viml/legacyconf.vim b/viml/legacyconf.vim index 7411451..f43365a 100644 --- a/viml/legacyconf.vim +++ b/viml/legacyconf.vim @@ -38,7 +38,7 @@ nnoremap :call Litde() " Theme nnoremap :colo morning -nnoremap :colo slate +nnoremap :colo tokyonight-night " Fuzzy finder nnoremap :Lines