From 8d1dea31b27a4bed25ca1f972a5e42d8bf231a19 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 22 Jun 2022 21:50:50 +0200 Subject: [PATCH] feat(wip): port nvim config to nix --- home-mandlm.nix | 116 +++++++++++++++++--- nvim/lua/keymaps.lua | 8 -- nvim/lua/options.lua | 8 -- nvim/lua/plugins.lua | 164 ---------------------------- nvim/lua/plugins/lspconfig.lua | 69 ++++++++++++ nvim/lua/plugins/nvim-cmp.lua | 4 +- nvim/lua/plugins/nvim-lsp-setup.lua | 1 + nvim/lua/plugins/treesitter.lua | 4 +- nvim/lua/themes.lua | 8 -- 9 files changed, 173 insertions(+), 209 deletions(-) diff --git a/home-mandlm.nix b/home-mandlm.nix index 0051347..96cd2d6 100644 --- a/home-mandlm.nix +++ b/home-mandlm.nix @@ -12,15 +12,9 @@ htop ripgrep pavucontrol - gcc - nodejs + gnumake unzip - cargo - rustc gcc - pkg-config - openssl - ]; slack thunderbird signal-desktop @@ -28,16 +22,13 @@ whatsapp-for-linux nextcloud-client keepassxc + direnv + tree - file = { - ".config/nvim/init.lua" = { - source = nvim/init.lua; - }; - ".config/nvim/lua" = { - source = nvim/lua; - recursive = true; - }; - }; + # LSP + sumneko-lua-language-server + rnix-lsp + ]; stateVersion = "22.05"; }; @@ -92,6 +83,99 @@ neovim = { enable = true; + plugins = with pkgs.vimPlugins; [ + # theme + nvim-solarized-lua + + delimitMate + vim-bbye + ansible-vim + + # session handling + vim-obsession + vim-prosession + + nvim-web-devicons + nvim-treesitter + markdown-preview-nvim # use({ "iamcco/markdown-preview.nvim", run = ":call mkdp#util#install()" }) + toggleterm-nvim + nvim-notify + comment-nvim + lualine-nvim + tabline-nvim + indent-blankline-nvim + plenary-nvim + + # git + gitsigns-nvim + vim-fugitive + gv-vim + + # snippets + friendly-snippets + luasnip + + # auto-completion + nvim-cmp + cmp-nvim-lsp + cmp-buffer + cmp-path + cmp-cmdline + cmp-nvim-lua + cmp_luasnip + cmp-calc + + # telescope + telescope-nvim + telescope-fzf-native-nvim + telescope-ui-select-nvim + + # LSP + nvim-lspconfig + lsp-status-nvim + ]; + + extraConfig = '' + lua << EOF + ${builtins.readFile ./nvim/lua/keymaps.lua } + ${builtins.readFile ./nvim/lua/options.lua } + ${builtins.readFile ./nvim/lua/plugins/treesitter.lua } + ${builtins.readFile ./nvim/lua/plugins/lspconfig.lua } + + require("toggleterm").setup({ size = 32, open_mapping = [[]] }) + + require("notify").setup({ stages = "fade" }) + vim.notify = require("notify") + + require('Comment').setup({}) + + require('lualine').setup({ + options = { globalstatus = true }, + sections = { + lualine_c = { { "filename", path = 1 }, "require('lsp-status').status()" } + }, + extensions = { "toggleterm" } + }) + + require('tabline').setup({ enable = true, options = { show_bufnr = true, show_filename_only = true }}) + + require("indent_blankline").setup { + char = "┊", + buftype_exclude = { "terminal", "help", "nofile" }, + filetype_exclude = { 'help', 'packer' }, + show_trailing_blankline_indent = false + } + + require('gitsigns').setup() + + require("luasnip.loaders.from_vscode").lazy_load() + + ${builtins.readFile ./nvim/lua/plugins/nvim-cmp.lua } + ${builtins.readFile ./nvim/lua/plugins/telescope.lua } + + ${builtins.readFile ./nvim/lua/themes.lua } + EOF + ''; }; tmux = { diff --git a/nvim/lua/keymaps.lua b/nvim/lua/keymaps.lua index 3b40c13..a3f0bde 100644 --- a/nvim/lua/keymaps.lua +++ b/nvim/lua/keymaps.lua @@ -1,11 +1,3 @@ --- source file everytime it changes -vim.cmd([[ - augroup user_keymaps - autocmd! - autocmd BufWritePost keymaps.lua source - augroup end -]]) - local function nnoremap(key, command) vim.api.nvim_set_keymap("n", key, command, { noremap = true }) end diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua index 87fde64..67d59c2 100644 --- a/nvim/lua/options.lua +++ b/nvim/lua/options.lua @@ -1,11 +1,3 @@ --- source file everytime it changes -vim.cmd([[ - augroup user_options - autocmd! - autocmd BufWritePost options.lua source - augroup end -]]) - -- termguicolors vim.opt.termguicolors = true diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index 62edcb0..f180b1b 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -1,115 +1,4 @@ -local fn = vim.fn - --- boostrap packer -local install_path = fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim' -local packer_bootstrap -if fn.empty(fn.glob(install_path)) > 0 then - packer_bootstrap = fn.system({ - 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', - install_path - }) -end - --- run PackerSync everytime plugins.lua is updated -vim.cmd([[ - augroup packer_user_config - autocmd! - autocmd BufWritePost plugins.lua source | PackerSync - augroup end -]]) - -vim.cmd([[packadd packer.nvim]]) - --- initialize plugins return require('packer').startup(function(use) - -- let packer manage itself - use({ 'wbthomason/packer.nvim', opt = true }) - - -- theme - use("ishan9299/nvim-solarized-lua") - - -- commenting - use { - 'numToStr/Comment.nvim', - config = function() require('Comment').setup({}) end - } - - -- session handling - use('tpope/vim-obsession') - use('dhruvasagar/vim-prosession') - - -- tabline - use { - 'kdheepak/tabline.nvim', - config = function() - require 'tabline'.setup { - enable = true, - options = { show_bufnr = true, show_filename_only = true } - } - end, - requires = { - { 'hoob3rt/lualine.nvim' }, - { 'kyazdani42/nvim-web-devicons', opt = true } - } - } - - -- status line - use { - 'nvim-lualine/lualine.nvim', - requires = { 'kyazdani42/nvim-web-devicons', opt = true }, - config = function() - require('lualine').setup({ - options = { globalstatus = true }, - sections = { - lualine_c = { { "filename", path = 1 }, "require('lsp-status').status()" } - }, - extensions = { "toggleterm" } - }) - end - } - - -- blankline - use({ - "lukas-reineke/indent-blankline.nvim", - config = function() - require("indent_blankline").setup { - char = "┊", - buftype_exclude = { "terminal", "help", "nofile" }, - filetype_exclude = { 'help', 'packer' }, - show_trailing_blankline_indent = false - } - end - }) - - -- git - use('tpope/vim-fugitive') - use({ - 'lewis6991/gitsigns.nvim', - requires = { 'nvim-lua/plenary.nvim' }, - config = function() require('gitsigns').setup() end - }) - use("junegunn/gv.vim") - - -- autocompletion - use({ - "L3MON4D3/LuaSnip", - requires = { "rafamadriz/friendly-snippets" }, - config = function() - require("luasnip.loaders.from_vscode").lazy_load() - end - }) - use({ - "hrsh7th/nvim-cmp", - requires = { - "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", - "hrsh7th/cmp-cmdline", "hrsh7th/cmp-git", "hrsh7th/cmp-nvim-lua", - "saadparwaiz1/cmp_luasnip", "hrsh7th/cmp-nvim-lsp-signature-help", - "davidsierradz/cmp-conventionalcommits", "hrsh7th/cmp-nvim-lua", - "hrsh7th/cmp-calc" - }, - config = function() require('plugins.nvim-cmp') end, - }) - -- language server use { 'junnplus/nvim-lsp-setup', @@ -135,9 +24,6 @@ return require('packer').startup(function(use) -- null-ls use { "jose-elias-alvarez/null-ls.nvim", - requres = { - { "nvim-lua/plenary.nvim" }, - }, config = function() require("null-ls").setup({ sources = { @@ -150,54 +36,4 @@ return require('packer').startup(function(use) }) end, } - - -- treesitter - use({ - 'nvim-treesitter/nvim-treesitter', - config = function() require('plugins.treesitter') end, - run = ':TSUpdate' - }) - - -- Telescope - use({ - "nvim-telescope/telescope.nvim", - requires = { - { "nvim-lua/plenary.nvim" }, - { "nvim-telescope/telescope-fzf-native.nvim", run = "make" }, - { "nvim-telescope/telescope-ui-select.nvim" }, - }, - config = function() require("plugins.telescope") end - }) - - -- automatic pairs - use({ "Raimondi/delimitMate" }) - - -- markdown preview - use({ "iamcco/markdown-preview.nvim", run = ":call mkdp#util#install()" }) - - -- terminal - use({ - "akinsho/nvim-toggleterm.lua", - config = function() - require("toggleterm").setup({ size = 32, open_mapping = [[]] }) - end - }) - - -- buffer closing - use({ "sar/bbye.nvim" }) - - -- ansible filetype - use({ "pearofducks/ansible-vim" }) - - -- nvim-notify - use({ "rcarriga/nvim-notify", - config = function() - require("notify").setup({ - stages = "fade", - }) - vim.notify = require("notify") - end - }) - - if packer_bootstrap then require('packer').sync() end end) diff --git a/nvim/lua/plugins/lspconfig.lua b/nvim/lua/plugins/lspconfig.lua index e69de29..2605b11 100644 --- a/nvim/lua/plugins/lspconfig.lua +++ b/nvim/lua/plugins/lspconfig.lua @@ -0,0 +1,69 @@ +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + +local on_attach = function(client, bufnr) + local function nnoremap(key, command) + vim.keymap.set("n", key, command, { noremap = true, silent = true, buffer = bufnr }) + end + + local telescope = require("telescope.builtin") + + nnoremap("gD", vim.lsp.buf.declaration) + nnoremap("gd", telescope.lsp_definitions) + nnoremap("gt", telescope.lsp_type_definitions) + nnoremap("gi", telescope.lsp_implementations) + nnoremap("gr", telescope.lsp_references) + nnoremap("K", vim.lsp.buf.hover) + nnoremap("", vim.lsp.buf.signature_help) + nnoremap("rn", vim.lsp.buf.rename) + nnoremap("ca", vim.lsp.buf.code_action) + nnoremap("f", vim.lsp.buf.formatting) + nnoremap("d", telescope.diagnostics) + nnoremap("", vim.diagnostic.goto_prev) + nnoremap("", vim.diagnostic.goto_next) + + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.formatting_sync() + end, + }) + end +end + +local lsp_status = require("lsp-status") +lsp_status.config({ + current_function = false, + show_filename = false, + diagnostics = true, +}) +lsp_status.register_progress() + +local capabilities = vim.tbl_extend("keep", vim.lsp.protocol.make_client_capabilities(), lsp_status.capabilities) +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) + +local servers = { + ["sumneko_lua"] = { + Lua = { + diagnostics = { + globals = { "vim" }, + }, + telemetry = { + enable = false, + }, + }, + }, + ["rnix"] = {}, +} + +local lspconfig = require("lspconfig") + +for lsp, config in pairs(servers) do + lspconfig[lsp].setup({ + settings = config or {}, + on_attach = on_attach, + capabilities = capabilities, + }) +end diff --git a/nvim/lua/plugins/nvim-cmp.lua b/nvim/lua/plugins/nvim-cmp.lua index 9261548..35c47ae 100644 --- a/nvim/lua/plugins/nvim-cmp.lua +++ b/nvim/lua/plugins/nvim-cmp.lua @@ -16,9 +16,7 @@ cmp.setup({ }, sources = require("cmp").config.sources({ { name = "nvim_lsp" }, { name = "luasnip" }, { name = "path" }, - { name = "buffer" }, { name = "git" }, - { name = 'nvim_lsp_signature_help' }, - { name = "conventionalcommits" }, { name = "nvim-lua" }, + { name = "buffer" }, { name = "git" }, { name = "nvim-lua" }, { name = "calc" } }), mapping = cmp.mapping.preset.insert({ diff --git a/nvim/lua/plugins/nvim-lsp-setup.lua b/nvim/lua/plugins/nvim-lsp-setup.lua index 8373633..0f16626 100644 --- a/nvim/lua/plugins/nvim-lsp-setup.lua +++ b/nvim/lua/plugins/nvim-lsp-setup.lua @@ -39,6 +39,7 @@ require("nvim-lsp-setup").setup({ eslint = {}, jsonls = {}, pylsp = {}, + rnix = {}, rust_analyzer = require("nvim-lsp-setup.rust-tools").setup({ server = { settings = { diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua index 45571c9..9191baa 100644 --- a/nvim/lua/plugins/treesitter.lua +++ b/nvim/lua/plugins/treesitter.lua @@ -3,7 +3,7 @@ require('nvim-treesitter.configs').setup({ indent = {enable = true}, ensure_installed = { "bash", "c", "cpp", "css", "dockerfile", "hcl", "html", "javascript", - "json", "latex", "lua", "markdown", "python", "rust", "svelte", "toml", - "tsx", "typescript", "vim", "vue", "yaml" + "json", "latex", "lua", "markdown", "nix", "python", "rust", "svelte", + "toml", "tsx", "typescript", "vim", "vue", "yaml" } }) diff --git a/nvim/lua/themes.lua b/nvim/lua/themes.lua index 53bc916..3101cab 100644 --- a/nvim/lua/themes.lua +++ b/nvim/lua/themes.lua @@ -1,10 +1,2 @@ --- source file everytime it changes -vim.cmd([[ - augroup user_theme_config - autocmd! - autocmd BufWritePost themes.lua source - augroup end -]]) - vim.opt.background = 'dark' vim.cmd("colorscheme solarized")