diff --git a/README.md b/README.md index 77f5161..348617f 100644 --- a/README.md +++ b/README.md @@ -99,11 +99,14 @@ To move seamlessly between splits. ### Autocompletion -Autocompletion is provided by [asyncomplete.vim](https://github.com/prabirshrestha/asyncomplete.vim). Additionally -LSP-based autocompletion is installed. +Autocomplete is provided by [nvim-cmp](https://github.com/hrsh7th/nvim-cmp). -Automatic popups are disabled. In order to see suggestions begin typing and then hit `` in insert mode. -Once in the popup you can use `` and `` to go up and down the suggestions. +Important commands: + +* ``: Will attempt to autocomplete your current line. +* ``: Will provide documentation and other details. + +This is, of course, depending entirely on which LSP you have installed. ### Default Leader diff --git a/lua/conf/langs/completion.lua b/lua/conf/langs/completion.lua new file mode 100644 index 0000000..1d3fb19 --- /dev/null +++ b/lua/conf/langs/completion.lua @@ -0,0 +1,54 @@ +-- Credit to https://rsdlt.github.io/ for this code. + +local cmp = require'cmp' + +cmp.setup({ + -- Enable LSP snippets + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Add tab support + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }) + }, + -- Installed sources: + sources = { + { name = 'path' }, -- file paths + { name = 'nvim_lsp', keyword_length = 3 }, -- from language server + { name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized + { name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.* + { name = 'buffer', keyword_length = 2 }, -- source current buffer + { name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip + { name = 'calc'}, -- source for math calculation + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon ={ + nvim_lsp = 'λ', + vsnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + item.menu = menu_icon[entry.source.name] + return item + end, + }, +}) diff --git a/lua/conf/langs/general.lua b/lua/conf/langs/general.lua index 8c15f5a..469de14 100644 --- a/lua/conf/langs/general.lua +++ b/lua/conf/langs/general.lua @@ -31,6 +31,7 @@ require'nvim-treesitter.configs'.setup { "markdown", "python", "rust", + "toml", "query", "vim", "vimdoc", @@ -55,4 +56,11 @@ require'nvim-treesitter.configs'.setup { -- Disable vim regex highlighting. May intefer with some `indent` style stuff. additional_vim_regex_highlighting = false, }, + ident = {enable = true }, + rainbow = { + enable = true, + extended_mode = true, + max_file_lines = nil, + } + } diff --git a/lua/conf/langs/rust.lua b/lua/conf/langs/rust.lua new file mode 100644 index 0000000..bcda183 --- /dev/null +++ b/lua/conf/langs/rust.lua @@ -0,0 +1,12 @@ +local rt = require("rust-tools") + +rt.setup({ + server = { + on_attach = function(_, bufnr) + -- Hover actions + vim.keymap.set("n", "", rt.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + vim.keymap.set("n", "a", rt.code_action_group.code_action_group, { buffer = bufnr }) + end, + }, +}) diff --git a/lua/conf/plugins.lua b/lua/conf/plugins.lua index dd83922..c062dec 100644 --- a/lua/conf/plugins.lua +++ b/lua/conf/plugins.lua @@ -10,7 +10,7 @@ vim.cmd [[ if !(has('win16') || has('win32') || has('win64')) if empty(glob('~/.config/nvim/autoload/plug.vim')) silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs - \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + \ https://raw.githubPlugrcontent.com/junegunn/vim-plug/master/plug.vim autocmd VimEnter * PlugInstall | source % endif endif @@ -47,9 +47,15 @@ Plug('williamboman/mason.nvim', {['do'] = vim.fn[':MasonUpdate']}) Plug('williamboman/mason-lspconfig.nvim') Plug('neovim/nvim-lspconfig') --- Autocomplete -Plug 'prabirshrestha/asyncomplete.vim' -Plug 'prabirshrestha/asyncomplete-lsp.vim' +-- Completion framework +Plug 'hrsh7th/nvim-cmp' +Plug 'hrsh7th/cmp-nvim-lsp' +Plug 'hrsh7th/cmp-nvim-lua' +Plug 'hrsh7th/cmp-nvim-lsp-signature-help' +Plug 'hrsh7th/cmp-vsnip' +Plug 'hrsh7th/cmp-path' +Plug 'hrsh7th/cmp-buffer' +Plug 'hrsh7th/vim-vsnip' -- Tmux Helper Plug 'preservim/vimux' @@ -78,4 +84,7 @@ if vim.fn.executable('pyenv') == 1 then Plug 'lambdalisue/vim-pyenv' end +-- Rust +Plug 'simrat39/rust-tools.nvim' + vim.call('plug#end') diff --git a/lua/conf/ui.lua b/lua/conf/ui.lua index 8227a58..ad373ed 100644 --- a/lua/conf/ui.lua +++ b/lua/conf/ui.lua @@ -9,11 +9,6 @@ vim.cmd [[colorscheme nord]] -- Always show hidden files in nerdtree vim.g.NERDTreeShowHidden = 1 --- Disable auto-popup for autocomplete --- This prevents autocomplete spamming when --- you dont want it. -vim.g.asyncomplete_auto_popup = 0 - require('telescope').setup{ defaults = {}, pickers = { @@ -23,6 +18,3 @@ require('telescope').setup{ }, extensions = {} } - - -