From e6a575d1b4b7f1e4b652f3bcb32ff2881021b206 Mon Sep 17 00:00:00 2001 From: the_4n0nym0u53 Date: Fri, 26 Nov 2021 17:20:07 +0100 Subject: [PATCH] Update init.vim Add LSP autocompletion and other stuff. --- nvim/.config/nvim/init.vim | 84 +++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim index 9b8eea5..5a597ba 100644 --- a/nvim/.config/nvim/init.vim +++ b/nvim/.config/nvim/init.vim @@ -12,12 +12,92 @@ Plug 'mengelbrecht/lightline-bufferline' Plug 'kyazdani42/nvim-web-devicons' Plug 'sheerun/vim-polyglot' Plug 'neovim/nvim-lspconfig' +Plug 'williamboman/nvim-lsp-installer' +Plug 'hrsh7th/cmp-nvim-lsp' +Plug 'hrsh7th/cmp-buffer' +Plug 'hrsh7th/cmp-path' +Plug 'hrsh7th/cmp-cmdline' +Plug 'hrsh7th/nvim-cmp' +Plug 'hrsh7th/cmp-vsnip' +Plug 'hrsh7th/vim-vsnip' call plug#end() """ LSP SETTINGS -lua require'lspconfig'.bashls.setup{} +lua << EOF + local lsp_installer = require("nvim-lsp-installer") + + -- Register a handler that will be called for all installed servers. + -- Alternatively, you may also register handlers on specific server instances instead (see example below). + lsp_installer.on_server_ready(function(server) + local opts = {} + + -- (optional) Customize the options passed to the server + -- if server.name == "tsserver" then + -- opts.root_dir = function() ... end + -- end + + -- This setup() function is exactly the same as lspconfig's setup function. + -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + server:setup(opts) + end) + + -- Setup nvim-cmp. + local cmp = require'cmp' + + cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + -- require'snippy'.expand_snippet(args.body) -- For `snippy` users. + end, + }, + mapping = { + [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [''] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + [''] = cmp.mapping.confirm({ select = true }), + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = 'buffer' }, + }) + }) + + -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' } + } + }) + + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) +EOF + + + +setl omnifunc=v:lua.vim.lsp.omnifunc """ BASIC SETTINGS @@ -61,6 +141,7 @@ let g:lightline.component_type = { 'buffers': 'tabsel' } " lightline-bufferline config let g:lightline#bufferline#show_number = 1 let g:lightline#bufferline#shorten_path = 0 +let g:lightline#bufferline#smart_path = 0 let g:lightline#bufferline#enable_devicons = 1 let g:lightline#bufferline#unnamed = '[No Name]' let g:lightline#bufferline#icon_position = 'right' @@ -94,4 +175,3 @@ nmap d7 lightline#bufferline#delete(7) nmap d8 lightline#bufferline#delete(8) nmap d9 lightline#bufferline#delete(9) nmap d0 lightline#bufferline#delete(10) -