From 01e3239e16a341590c463020d0c902d50ee8a49c Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Mon, 30 Oct 2023 21:37:23 +0100 Subject: [PATCH] split neovim config into multiple files --- home-manager/neovim/bufferline.lua | 14 +++ home-manager/neovim/cmp.lua | 46 ++++++++ home-manager/neovim/core.lua | 9 ++ home-manager/neovim/default.nix | 50 +++++++-- home-manager/neovim/leap.lua | 4 + home-manager/neovim/lspconfig.lua | 33 ++++++ home-manager/neovim/neovim.lua | 171 ----------------------------- home-manager/neovim/telescope.lua | 27 +++++ home-manager/neovim/treesitter.lua | 9 ++ 9 files changed, 183 insertions(+), 180 deletions(-) create mode 100644 home-manager/neovim/bufferline.lua create mode 100644 home-manager/neovim/cmp.lua create mode 100644 home-manager/neovim/core.lua create mode 100644 home-manager/neovim/leap.lua create mode 100644 home-manager/neovim/lspconfig.lua delete mode 100644 home-manager/neovim/neovim.lua create mode 100644 home-manager/neovim/telescope.lua create mode 100644 home-manager/neovim/treesitter.lua diff --git a/home-manager/neovim/bufferline.lua b/home-manager/neovim/bufferline.lua new file mode 100644 index 0000000..d06e198 --- /dev/null +++ b/home-manager/neovim/bufferline.lua @@ -0,0 +1,14 @@ +require("bufferline").setup{ + options = { + diagnostics = 'nvim_lsp', + diagnostics_indicator = function(count, level, diagnostics_dict, context) + local icon = level:match("error") and " " or " " + return " " .. icon .. count + end, + separator_style = "slant", + hover = { + enabled = true, + reveal = {'close'}, + }, + }, +} diff --git a/home-manager/neovim/cmp.lua b/home-manager/neovim/cmp.lua new file mode 100644 index 0000000..cf2b7a7 --- /dev/null +++ b/home-manager/neovim/cmp.lua @@ -0,0 +1,46 @@ +local cmp = require('cmp') +local luasnip = require('luasnip') + +require('luasnip.loaders.from_vscode').lazy_load() +luasnip.config.setup {} + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete {}, + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} diff --git a/home-manager/neovim/core.lua b/home-manager/neovim/core.lua new file mode 100644 index 0000000..93c0dc2 --- /dev/null +++ b/home-manager/neovim/core.lua @@ -0,0 +1,9 @@ +vim.o.background = "dark" +vim.cmd([[colorscheme gruvbox]]) +vim.g.mapleader = ";" +vim.o.signcolumn = "yes" +vim.wo.number = true +vim.wo.relativenumber = true +vim.wo.cursorline = true +vim.opt.termguicolors = true +vim.o.mousemoveevent = true diff --git a/home-manager/neovim/default.nix b/home-manager/neovim/default.nix index fa27e23..7efbac9 100644 --- a/home-manager/neovim/default.nix +++ b/home-manager/neovim/default.nix @@ -8,7 +8,7 @@ vimAlias = true; vimdiffAlias = true; defaultEditor = true; - extraLuaConfig = builtins.readFile ./neovim.lua; + extraLuaConfig = builtins.readFile ./core.lua; extraPackages = with pkgs; [ nil @@ -19,21 +19,53 @@ ]; plugins = with pkgs.vimPlugins; [ - nvim-lspconfig + { + plugin = nvim-lspconfig; + type = "lua"; + config = builtins.readFile ./lspconfig.lua; + } gruvbox-nvim - leap-nvim - telescope-nvim - vim-commentary + { + plugin = leap-nvim; + type = "lua"; + config = builtins.readFile ./leap.lua; + } + { + plugin = telescope-nvim; + type = "lua"; + config = builtins.readFile ./telescope.lua; + } + { + plugin = vim-commentary; + type = "lua"; + config = "vim.cmd([[autocmd FileType nix setlocal commentstring=#\ %s]])"; + } vim-sleuth - gitsigns-nvim - nvim-cmp + { + plugin = gitsigns-nvim; + type = "lua"; + config = "require(\"gitsigns\").setup()"; + } + { + plugin = nvim-cmp; + type = "lua"; + config = builtins.readFile ./cmp.lua; + } cmp-nvim-lsp friendly-snippets neodev-nvim luasnip cmp_luasnip - nvim-treesitter.withAllGrammars - bufferline-nvim + { + plugin = nvim-treesitter.withAllGrammars; + type = "lua"; + config = builtins.readFile ./treesitter.lua; + } + { + plugin = bufferline-nvim; + type = "lua"; + config = builtins.readFile ./bufferline.lua; + } nvim-web-devicons ]; }; diff --git a/home-manager/neovim/leap.lua b/home-manager/neovim/leap.lua new file mode 100644 index 0000000..9f4ce6b --- /dev/null +++ b/home-manager/neovim/leap.lua @@ -0,0 +1,4 @@ +require('leap').add_default_mappings() +-- Don't remap 'x' in visual mode. +vim.keymap.del({'x', 'o'}, 'x') +vim.keymap.del({'x', 'o'}, 'X') diff --git a/home-manager/neovim/lspconfig.lua b/home-manager/neovim/lspconfig.lua new file mode 100644 index 0000000..abe6e13 --- /dev/null +++ b/home-manager/neovim/lspconfig.lua @@ -0,0 +1,33 @@ +local on_attach = function(_, bufnr) + + local bufmap = function(keys, func) + vim.keymap.set('n', keys, func, { buffer = bufnr }) + end + + bufmap('r', vim.lsp.buf.rename) + bufmap('a', vim.lsp.buf.code_action) + + bufmap('gd', vim.lsp.buf.definition) + bufmap('gD', vim.lsp.buf.declaration) + bufmap('gI', vim.lsp.buf.implementation) + bufmap('D', vim.lsp.buf.type_definition) + + bufmap('gr', require('telescope.builtin').lsp_references) + bufmap('s', require('telescope.builtin').lsp_document_symbols) + bufmap('S', require('telescope.builtin').lsp_dynamic_workspace_symbols) + + bufmap('K', vim.lsp.buf.hover) + + vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) + vim.lsp.buf.format() + end, {}) +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + +require('neodev').setup() +require'lspconfig'.nil_ls.setup{ on_attach = on_attach, capabilities = capabilities } +require'lspconfig'.pyright.setup{ on_attach = on_attach, capabilities = capabilities } +require'lspconfig'.gopls.setup{ on_attach = on_attach, capabilities = capabilities } +require'lspconfig'.terraformls.setup{ on_attach = on_attach, capabilities = capabilities } diff --git a/home-manager/neovim/neovim.lua b/home-manager/neovim/neovim.lua deleted file mode 100644 index 594e16c..0000000 --- a/home-manager/neovim/neovim.lua +++ /dev/null @@ -1,171 +0,0 @@ ---[ GLOBAL ]-- - -vim.o.background = "dark" -vim.cmd([[colorscheme gruvbox]]) -vim.g.mapleader = ";" -vim.o.signcolumn = "yes" -vim.wo.number = true -vim.wo.relativenumber = true -vim.wo.cursorline = true -vim.opt.termguicolors = true -vim.o.mousemoveevent = true - ---[ LSPCONFIG ]-- - -local on_attach = function(_, bufnr) - - local bufmap = function(keys, func) - vim.keymap.set('n', keys, func, { buffer = bufnr }) - end - - bufmap('r', vim.lsp.buf.rename) - bufmap('a', vim.lsp.buf.code_action) - - bufmap('gd', vim.lsp.buf.definition) - bufmap('gD', vim.lsp.buf.declaration) - bufmap('gI', vim.lsp.buf.implementation) - bufmap('D', vim.lsp.buf.type_definition) - - bufmap('gr', require('telescope.builtin').lsp_references) - bufmap('s', require('telescope.builtin').lsp_document_symbols) - bufmap('S', require('telescope.builtin').lsp_dynamic_workspace_symbols) - - bufmap('K', vim.lsp.buf.hover) - - vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) - vim.lsp.buf.format() - end, {}) -end - -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - -require('neodev').setup() -require'lspconfig'.nil_ls.setup{ on_attach = on_attach, capabilities = capabilities } -require'lspconfig'.pyright.setup{ on_attach = on_attach, capabilities = capabilities } -require'lspconfig'.gopls.setup{ on_attach = on_attach, capabilities = capabilities } -require'lspconfig'.terraformls.setup{ on_attach = on_attach, capabilities = capabilities } - ---[ LEAP ]-- - -require('leap').add_default_mappings() --- Don't remap 'x' in visual mode. -vim.keymap.del({'x', 'o'}, 'x') -vim.keymap.del({'x', 'o'}, 'X') - ---[ TELESCOPE ]-- - -local builtin = require('telescope.builtin') - -vim.keymap.set('n', 'ff', builtin.find_files, {}) -vim.keymap.set('n', 'fg', builtin.live_grep, {}) -vim.keymap.set('n', 'fb', builtin.buffers, {}) -vim.keymap.set('n', 'fr', builtin.lsp_references, {}) -vim.keymap.set('n', 'fs', builtin.lsp_document_symbols, {}) - -require('telescope').setup{ - pickers = { - find_files = { - theme = "dropdown" - }, - live_grep = { - theme = "dropdown" - }, - buffers = { - theme = "dropdown" - }, - lsp_references = { - theme = "dropdown" - }, - lsp_document_symbols = { - theme = "dropdown" - } - } -} - ---[ COMMENTARY ]-- - -vim.cmd([[autocmd FileType nix setlocal commentstring=#\ %s]]) - ---[ GITSIGNS ]-- - -require("gitsigns").setup() - ---[ CMP ]-- - -local cmp = require('cmp') -local luasnip = require('luasnip') - -require('luasnip.loaders.from_vscode').lazy_load() -luasnip.config.setup {} - -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert { - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete {}, - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { 'i', 's' }), - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, -} - ---[ TREESITTER ]-- - -require('nvim-treesitter.configs').setup { - ensure_installed = {}, - - auto_install = false, - - highlight = { enable = true }, - - indent = { enable = true }, -} - ---[ BUFFERLINE ]-- - -require("bufferline").setup{ - options = { - diagnostics = 'nvim_lsp', - diagnostics_indicator = function(count, level, diagnostics_dict, context) - local icon = level:match("error") and " " or " " - return " " .. icon .. count - end, - separator_style = "slant", - hover = { - enabled = true, - reveal = {'close'}, - }, - }, -} -require("bufferline").seperator_style = "slanted" diff --git a/home-manager/neovim/telescope.lua b/home-manager/neovim/telescope.lua new file mode 100644 index 0000000..59c0ffc --- /dev/null +++ b/home-manager/neovim/telescope.lua @@ -0,0 +1,27 @@ +local builtin = require('telescope.builtin') + +vim.keymap.set('n', 'ff', builtin.find_files, {}) +vim.keymap.set('n', 'fg', builtin.live_grep, {}) +vim.keymap.set('n', 'fb', builtin.buffers, {}) +vim.keymap.set('n', 'fr', builtin.lsp_references, {}) +vim.keymap.set('n', 'fs', builtin.lsp_document_symbols, {}) + +require('telescope').setup{ + pickers = { + find_files = { + theme = "dropdown" + }, + live_grep = { + theme = "dropdown" + }, + buffers = { + theme = "dropdown" + }, + lsp_references = { + theme = "dropdown" + }, + lsp_document_symbols = { + theme = "dropdown" + } + } +} diff --git a/home-manager/neovim/treesitter.lua b/home-manager/neovim/treesitter.lua new file mode 100644 index 0000000..2edb953 --- /dev/null +++ b/home-manager/neovim/treesitter.lua @@ -0,0 +1,9 @@ +require('nvim-treesitter.configs').setup { + ensure_installed = {}, + + auto_install = false, + + highlight = { enable = true }, + + indent = { enable = true }, +}