From 802d769a9cce8eec83cfa2027533f29b522eb8f1 Mon Sep 17 00:00:00 2001 From: tiyn Date: Sat, 14 Jan 2023 05:12:21 +0100 Subject: [PATCH] nvim: setup automatic loading with mason and other plugins --- .config/nvim/lua/keymap.lua | 20 ++++------ .config/nvim/lua/loadplugins.lua | 49 ++++++++++++++++--------- .config/nvim/plugin/nvim-autopairs.lua | 1 + .config/nvim/plugin/nvim-cmp.lua | 24 +++++++++++- .config/nvim/plugin/nvim-treesitter.lua | 19 ++++++++++ 5 files changed, 83 insertions(+), 30 deletions(-) create mode 100644 .config/nvim/plugin/nvim-autopairs.lua create mode 100644 .config/nvim/plugin/nvim-treesitter.lua diff --git a/.config/nvim/lua/keymap.lua b/.config/nvim/lua/keymap.lua index 458b55c..0e1b980 100644 --- a/.config/nvim/lua/keymap.lua +++ b/.config/nvim/lua/keymap.lua @@ -65,15 +65,11 @@ vim.api.nvim_set_keymap('n', 'gu', ':diffget //2', { noremap = true vim.api.nvim_set_keymap('n', 'gs', ':G', { noremap = true }) -- hrsh7th/nvim-cmp -local on_attach = function(client, bufnr) - local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - local opts = { noremap=true, silent=true } - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'gy', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', '', 'lua vim.lsp.buf.rename()', opts) -end +vim.api.nvim_set_keymap('n', 'gD', ':lua vim.lsp.buf.declaration()', { noremap = true }) +vim.api.nvim_set_keymap('n', 'gd', ':lua vim.lsp.buf.definition()', { noremap = true }) +vim.api.nvim_set_keymap('n', 'gy', ':lua vim.lsp.buf.type_definition()', { noremap = true }) +vim.api.nvim_set_keymap('n', 'gi', ':lua vim.lsp.buf.implementation()', { noremap = true }) +vim.api.nvim_set_keymap('n', 'gr', ':lua vim.lsp.buf.references()', { noremap = true }) +vim.api.nvim_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()', { noremap = true }) +vim.api.nvim_set_keymap('n', '', ':lua vim.lsp.buf.rename()', { noremap = true }) +vim.api.nvim_set_keymap('n', '', ':lua vim.lsp.buf.format()', { noremap = true }) diff --git a/.config/nvim/lua/loadplugins.lua b/.config/nvim/lua/loadplugins.lua index bbcbc51..3eac7f0 100644 --- a/.config/nvim/lua/loadplugins.lua +++ b/.config/nvim/lua/loadplugins.lua @@ -16,14 +16,8 @@ local packer_bootstrap = ensure_packer() -- load plugins with packer return require("packer").startup(function(use) - -- package manager - use 'wbthomason/packer.nvim' - if packer_bootstrap then - require('packer').sync() - end - - -- automatic closing of brackets - use 'raimondi/delimitmate' + -- package manager (first entry) + use {'wbthomason/packer.nvim'} -- improved java syntax highlighting use {'uiiaoo/java-syntax.vim', @@ -43,7 +37,11 @@ return require("packer").startup(function(use) requires = 'ryanoasis/vim-devicons'} -- nim language support - use {'zah/nim.vim', ft = {'nim'}} + use {'zah/nim.vim', + ft = {'nim'}} + + -- automatic closing of brackets + use {'windwp/nvim-autopairs'} -- autocompletion and its sources use {'hrsh7th/nvim-cmp', @@ -53,23 +51,35 @@ return require("packer").startup(function(use) 'l3mon4d3/luasnip', 'saadparwaiz1/cmp_luasnip', 'neovim/nvim-lspconfig', - 'onsails/lspkind-nvim'}} + 'onsails/lspkind-nvim', + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + 'jose-elias-alvarez/null-ls.nvim', + 'nvim-lua/plenary.nvim', + 'jayp0521/mason-null-ls.nvim'}} -- showing color of hex values, etc - use 'norcalli/nvim-colorizer.lua' + use {'norcalli/nvim-colorizer.lua'} + + -- better language highlighting by improved parsing + use {'nvim-treesitter/nvim-treesitter'} + + -- automatically close html-tags + use {'windwp/nvim-ts-autotag', + requires = {'nvim-treesitter/nvim-treesitter'}} -- colorful brackets - use 'luochen1990/rainbow' + use {'luochen1990/rainbow'} -- show tags use {'majutsushi/tagbar', cmd = 'TagbarToggle'} -- git wrapper - use 'tpope/vim-fugitive' + use {'tpope/vim-fugitive'} -- indicate git diff status of line - use 'airblade/vim-gitgutter' + use {'airblade/vim-gitgutter'} -- golang language support use {'fatih/vim-go', @@ -81,12 +91,17 @@ return require("packer").startup(function(use) requires = {'godlygeek/tabular'}} -- bulk renamer - use 'qpkorr/vim-renamer' + use {'qpkorr/vim-renamer'} -- additional quote/parantheses funtions - use 'tpope/vim-surround' + use {'tpope/vim-surround'} -- colorscheme - use 'tiyn/vim-tccs' + use {'tiyn/vim-tccs'} + + -- package manager sync (last entry) + if packer_bootstrap then + require('packer').sync() + end end) diff --git a/.config/nvim/plugin/nvim-autopairs.lua b/.config/nvim/plugin/nvim-autopairs.lua new file mode 100644 index 0000000..ba62d44 --- /dev/null +++ b/.config/nvim/plugin/nvim-autopairs.lua @@ -0,0 +1 @@ +require("nvim-autopairs").setup {} diff --git a/.config/nvim/plugin/nvim-cmp.lua b/.config/nvim/plugin/nvim-cmp.lua index a493bb6..e6e8b0a 100644 --- a/.config/nvim/plugin/nvim-cmp.lua +++ b/.config/nvim/plugin/nvim-cmp.lua @@ -1,4 +1,26 @@ -- hrsh7th/nvim-cmp + +-- mason package manager +require("mason").setup() +require("mason-lspconfig").setup({ + -- automatically install language servers setup below for lspconfig + automatic_setup = true, +}) + +-- jose-elias-alvarez/null-ls.nvim +local null_ls = require("null-ls") + +null_ls.setup({ + sources = { + null_ls.builtins.formatting.autopep8, + null_ls.builtins.formatting.nimpretty, + }, +}) + +require("mason-null-ls").setup({ + automatic_installation = true +}) + -- Add additional capabilities supported by nvim-cmp capabilities = require("cmp_nvim_lsp").default_capabilities() @@ -94,7 +116,7 @@ local nvim_lsp = require('lspconfig') -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches -local servers = { "pyright", "bashls", "tsserver", "texlab", "ccls", "gopls", "hls", "nimls", "marksman" } +local servers = { "pyright", "bashls", "texlab", "ccls", "nimls", "marksman" } for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { on_attach=on_attach, diff --git a/.config/nvim/plugin/nvim-treesitter.lua b/.config/nvim/plugin/nvim-treesitter.lua new file mode 100644 index 0000000..e16154a --- /dev/null +++ b/.config/nvim/plugin/nvim-treesitter.lua @@ -0,0 +1,19 @@ +-- nvim-treesitter/nvim-treesitter + +local ts_config = require "nvim-treesitter.configs" + +ts_config.setup { + ensure_installed = { + "bash", + "c", + "cpp", + "css", + "html", + "java", + "markdown", + "latex", + "python", + }, + + autotag = { enable = true }, +}