From a17bf71016b948b216a82fe97099873f2c9802ca Mon Sep 17 00:00:00 2001 From: Ivan Polyakov Date: Tue, 28 Jun 2022 19:25:34 +0300 Subject: [PATCH] nvim completions --- .config/nvim/init.vim | 64 +++++++++++++++++++++++++----------- .config/nvim/lua/plugins.lua | 18 +++++++--- 2 files changed, 58 insertions(+), 24 deletions(-) diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 793cb0b..4dccbbf 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -9,6 +9,8 @@ set cc=75 " show column ruler set ts=4 set shiftwidth=4 set expandtab +set scrolloff=2 +set completeopt=menu,menuone,noselect """ Colors syntax on @@ -63,33 +65,57 @@ let g:vimtex_syntax_conceal = { \} set conceallevel=2 -"" LSP -"" See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md lua << EOF +-- LSP and completions -- +-- Completions -- +local cmp = require('cmp') +cmp.setup({ + completion = { autocomplete = false }, + snippet = { + expand = function (args) + require('snippy').expand_snippet(args.body) + end, + }, + mapping = { + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'snippy' } + }) +}) + +-- LSP -- +-- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md local lsp = require('lspconfig') +local capabilities = require('cmp_nvim_lsp') + .update_capabilities(vim.lsp.protocol.make_client_capabilities()) + lsp.clangd.setup { - filetypes = { "c", "cpp", "cxx" } + filetypes = { 'c', 'cpp', 'cxx' }, + capabilities = capabilities } -lsp.eslint.setup{} +lsp.eslint.setup { + capabilities = capabilities +} lsp.sumneko_lua.setup { - settings = { - Lua = { - runtime = { - version = 'LuaJIT', - }, - diagnostics = { - globals = {'vim'}, - }, - workspace = { - library = vim.api.nvim_get_runtime_file("", true), - }, - telemetry = { - enable = false, - }, + settings = { + Lua = { + runtime = { version = 'LuaJIT' }, + diagnostics = { globals = { 'vim' } }, + workspace = { + library = vim.api.nvim_get_runtime_file('', true), + }, + telemetry = { enable = false }, + }, }, - }, + capabilities = capabilities, } EOF diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index f3bda22..fb33b44 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -1,31 +1,39 @@ return require('packer').startup(function() use 'wbthomason/packer.nvim' + -- Look and feel -- use 'shaunsingh/nord.nvim' - use { 'nvim-lualine/lualine.nvim', requires = { 'kyazdani42/nvim-web-devicons', opt = true } } - use 'preservim/nerdtree' - use 'dcampos/nvim-snippy' + -- Snippets -- + use 'dcampos/nvim-snippy' use 'honza/vim-snippets' + + -- Languages -- use { 'lervag/vimtex', tag = 'v2.9', ft = 'tex' } - use { 'digitaltoad/vim-pug', ft = {'pug', 'vue'} } + + -- LSP and completions -- use 'neovim/nvim-lspconfig' + use 'hrsh7th/nvim-cmp' + use 'hrsh7th/cmp-nvim-lsp' + use 'dcampos/cmp-snippy' -- Completions for snippets + - use 'MunifTanjim/nui.nvim' + -- Another tools -- + use 'MunifTanjim/nui.nvim' -- UI framework end)