Major refactor of code completion, now very much nicer

This commit is contained in:
Yannick Reiß 2023-09-04 15:26:51 +02:00
parent 56f3b08936
commit dfd2dda8d0
No known key found for this signature in database
GPG Key ID: 5A3AF456F0A0338C
4 changed files with 92 additions and 91 deletions

View File

@ -21,7 +21,7 @@ vim.opt.guifont = "DroidSansMono Nerd Font 11"
-- set colorscheme -- set colorscheme
vim.opt.termguicolors = true vim.opt.termguicolors = true
vim.cmd([[ vim.cmd([[
colorscheme slate colorscheme tokyonight-night
]]) ]])
-- vim.cmd('source ~/.config/nvim/viml/plugins.vim') -- vim.cmd('source ~/.config/nvim/viml/plugins.vim')
@ -162,15 +162,6 @@ require("mason-lspconfig").setup_handlers({
end, end,
}) })
local wilder = require("wilder")
wilder.setup({
modes = { ":", "/", "?" },
next_key = "<Tab>",
previous_key = "<S-Tab>",
accept_key = "<c-k>",
reject_key = "<Up>",
})
require("code-completion") require("code-completion")
-- neovide configuration -- neovide configuration
@ -180,4 +171,3 @@ if vim.g.neovide then
end end
vim.cmd("source ~/.config/nvim/viml/legacyconf.vim") vim.cmd("source ~/.config/nvim/viml/legacyconf.vim")
vim.cmd("source ~/.config/nvim/viml/macros.vim")

View File

@ -2,93 +2,101 @@
-- noinsert: only insert text when selection confirmed -- noinsert: only insert text when selection confirmed
-- noselect: force to select from suggestion -- noselect: force to select from suggestion
-- preview: show more details -- preview: show more details
vim.opt.completeopt = {'menuone', 'noselect', 'noinsert', 'preview'} vim.opt.completeopt = { "menu", "menuone" }
-- shortmess is used to reduce verbocity -- shortmess is used to reduce verbocity
-- vim.opt.shortmess = vim.opt.shortmess + { c = true } -- vim.opt.shortmess = vim.opt.shortmess + { c = true }
local cmp = require("cmp")
local cmp = require'cmp' cmp.setup({
cmp.setup( {
-- configuration -- configuration
snippet = { snippet = {
expand = function(args) expand = function(args)
vim.fn["UltiSnips#Anon"](args.body) vim.fn["UltiSnips#Anon"](args.body)
end, end,
}, },
-- mapping
mapping = {
-- Shift+TAB to go to the Previous Suggested item
['<C-s-k>'] = cmp.mapping.select_prev_item(),
-- Tab to go to the next suggestion
['<C-k>'] = cmp.mapping.select_next_item(),
-- CTRL+SHIFT+f to scroll backwards in description
['<C-S-f>'] = cmp.mapping.scroll_docs(-4),
-- CTRL+F to scroll forwards in the description
['<C-f>'] = cmp.mapping.scroll_docs(4),
-- CTRL+SPACE to bring up completion at current Cursor location
['<C-Space>'] = cmp.mapping.complete(),
-- CTRL+e to exit suggestion and close it
['<C-e>'] = cmp.mapping.close(),
-- CR (enter or return) to CONFIRM the currently selection suggestion
-- We set the ConfirmBehavior to insert the Selected suggestion
['<CR>'] = 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 } }
},
-- Add borders to the windows -- Add borders to the windows
window = { window = {
completion = cmp.config.window.bordered(), completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(),
}, },
-- add formating of the different sources
-- mapping
mapping = cmp.mapping.preset.insert({
-- Shift+TAB to go to the Previous Suggested item
["<C-s-k>"] = cmp.mapping.select_prev_item(),
-- Tab to go to the next suggestion
["<C-k>"] = cmp.mapping.select_next_item(),
-- CTRL+SHIFT+f to scroll backwards in description
["<C-S-f>"] = cmp.mapping.scroll_docs(-4),
-- CTRL+F to scroll forwards in the description
["<C-f>"] = cmp.mapping.scroll_docs(4),
-- CTRL+SPACE to bring up completion at current Cursor location
["<C-Space>"] = cmp.mapping.complete(),
-- CTRL+e to exit suggestion and close it
["<C-s-CR>"] = 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
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
}),
}),
-- installed sources for code suggestion
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 formatting of the different sources
formatting = { formatting = {
fields = {'menu', 'abbr', 'kind'}, fields = { "menu", "abbr", "kind" },
format = function(entry, item) format = function(entry, item)
local menu_icon ={ local menu_icon = {
nvim_lsp = 'λ', nvim_lsp = "λ",
ultisnips = '', ultisnips = "",
buffer = 'b', buffer = "b",
path = 'p', path = "p",
calc = 'Σ', calc = "Σ",
lualatexsymbols = 'L' lualatexsymbols = "L",
} }
item.menu = menu_icon[entry.source.name] item.menu = menu_icon[entry.source.name]
return item return item
end, end,
} },
} ) })
-- Set configuration for specific filetype. -- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', { cmp.setup.filetype("gitcommit", {
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. { name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it.
}, { }, {
{ name = 'buffer' }, { 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). -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', { cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'path' } { name = "path" },
{ name = "cmdline_history", keyword_length = 15 },
}, { }, {
{ name = 'cmdline' } { name = "cmdline" },
}) }),
}) })

View File

@ -1,12 +1,13 @@
return require("packer").startup(function(use) return require("packer").startup(function(use)
-- Configurations will go here soon -- Configurations will go here soon
use("wbthomason/packer.nvim") use("wbthomason/packer.nvim")
-- use 'dense-analysis/ale'
use("preservim/nerdtree") use("preservim/nerdtree")
use("Xuyuanp/nerdtree-git-plugin") use("Xuyuanp/nerdtree-git-plugin")
use("tpope/vim-surround") use("tpope/vim-surround")
use("SirVer/ultisnips") use("SirVer/ultisnips")
use("powerline/powerline")
use("vim-airline/vim-airline") use("vim-airline/vim-airline")
use("vim-airline/vim-airline-themes")
use({ use({
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
run = function() run = function()
@ -14,7 +15,6 @@ return require("packer").startup(function(use)
ts_update() ts_update()
end, end,
}) })
use({ "gelguy/wilder.nvim" })
use({ "junegunn/fzf", run = ":call fzf#install()" }) use({ "junegunn/fzf", run = ":call fzf#install()" })
use("junegunn/fzf.vim") use("junegunn/fzf.vim")
use("williamboman/mason.nvim") use("williamboman/mason.nvim")
@ -33,6 +33,8 @@ return require("packer").startup(function(use)
use("hrsh7th/cmp-path") use("hrsh7th/cmp-path")
use("hrsh7th/cmp-buffer") use("hrsh7th/cmp-buffer")
use("hrsh7th/cmp-calc") use("hrsh7th/cmp-calc")
use("hrsh7th/cmp-cmdline")
use("dmitmel/cmp-cmdline-history")
use("amarakon/nvim-cmp-lua-latex-symbols") use("amarakon/nvim-cmp-lua-latex-symbols")
use("prabirshrestha/async.vim") use("prabirshrestha/async.vim")
use("prabirshrestha/vim-lsp") use("prabirshrestha/vim-lsp")
@ -44,4 +46,5 @@ return require("packer").startup(function(use)
use("ryanoasis/vim-devicons") use("ryanoasis/vim-devicons")
use("mhartington/formatter.nvim") use("mhartington/formatter.nvim")
use("tzachar/highlight-undo.nvim") use("tzachar/highlight-undo.nvim")
use("folke/tokyonight.nvim")
end) end)

View File

@ -38,7 +38,7 @@ nnoremap <C-g> :call Litde()<CR>
" Theme " Theme
nnoremap <M-+> :colo morning<CR> nnoremap <M-+> :colo morning<CR>
nnoremap <M--> :colo slate<CR> nnoremap <M--> :colo tokyonight-night<CR>
" Fuzzy finder " Fuzzy finder
nnoremap <C-f> :Lines<CR> nnoremap <C-f> :Lines<CR>