From 5ebf139b8f1ff9ca23d686bd0dfca16dd4aab5f6 Mon Sep 17 00:00:00 2001 From: fuckwit Date: Mon, 4 Nov 2024 18:05:01 +0100 Subject: [PATCH] add nvim config --- home-modules/firefox-webapp.nix | 2 +- home/work/programs/bash/default.nix | 2 +- home/work/programs/default.nix | 1 + home/work/programs/nvim/default.nix | 329 ++++++++++++++++++++++++++++ 4 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 home/work/programs/nvim/default.nix diff --git a/home-modules/firefox-webapp.nix b/home-modules/firefox-webapp.nix index 1fbbfe4..a5b452d 100644 --- a/home-modules/firefox-webapp.nix +++ b/home-modules/firefox-webapp.nix @@ -14,7 +14,7 @@ nameValuePair "home-manager-webapp-${name}" { id = cfg.id; - userChrome = '' + userChrome = /* css */ '' @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); browser { diff --git a/home/work/programs/bash/default.nix b/home/work/programs/bash/default.nix index f3d6755..e68a39b 100644 --- a/home/work/programs/bash/default.nix +++ b/home/work/programs/bash/default.nix @@ -9,7 +9,7 @@ rescue = "ssh-wrapper rescue"; }; - initExtra = '' + initExtra = /* bash */ '' source ${pkgs.blesh}/share/blesh/ble.sh export PATH=$PATH:~/.local/bin export SSH_AUTH_SOCK=/run/user/1000/ssh-agent diff --git a/home/work/programs/default.nix b/home/work/programs/default.nix index 7d78415..8e14f9e 100644 --- a/home/work/programs/default.nix +++ b/home/work/programs/default.nix @@ -3,6 +3,7 @@ ./autorandr ./bash ./firefox + ./nvim ./rofi ./tmate ./xresources diff --git a/home/work/programs/nvim/default.nix b/home/work/programs/nvim/default.nix new file mode 100644 index 0000000..17946fa --- /dev/null +++ b/home/work/programs/nvim/default.nix @@ -0,0 +1,329 @@ +{pkgs, ...}: { + programs.neovim = { + enable = true; + defaultEditor = true; + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + withRuby = false; + withPython3 = false; + + plugins = with pkgs.vimPlugins; [ + vim-commentary + plenary-nvim + cmp-nvim-lsp + cmp-buffer + cmp-path + nvim-web-devicons + lsp_extensions-nvim + lsp_signature-nvim + telescope-nvim + onedark-nvim + { + plugin = fidget-nvim; + type = "lua"; + config = /* lua */ '' + require('fidget').setup {} + ''; + } + { + plugin = symbols-outline-nvim; + type = "lua"; + config = /* lua */ '' + require('symbols-outline').setup() + ''; + } + { + plugin = nvim-treesitter.withAllGrammars; + type = "lua"; + config = /* lua */ '' + require('nvim-treesitter.configs').setup { + highlight = { + enable = true, -- false will disable the whole extension + }, + incremental_selection = { + enable = false, + keymaps = { + init_selection = 'gnn', + node_incremental = 'grn', + scope_incremental = 'grc', + node_decremental = 'grm', + }, + }, + indent = { + enable = true, + } + } + ''; + } + { + plugin = nvim-tree-lua; + type = "lua"; + config = /* lua */ '' + local function my_on_attach(bufnr) + local api = require "nvim-tree.api" + + local function opts(desc) + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + + -- default mappings + api.config.mappings.default_on_attach(bufnr) + + -- custom mappings + vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help')) + vim.keymap.set('n', 's', api.node.open.horizontal, opts('Paste File')) + vim.keymap.set('n', 'ma', api.fs.create, opts('New File')) + vim.keymap.set('n', 'md', api.fs.remove, opts('Delete File')) + vim.keymap.set('n', 'me', api.fs.rename_node, opts('Rename File')) + vim.keymap.set('n', 'yy', api.fs.copy.node, opts('Copy File')) + vim.keymap.set('n', 'mp', api.fs.paste, opts('Paste File')) + end + + require("nvim-tree").setup { + on_attach = my_on_attach, + } + ''; + } + { + plugin = nvim-cmp; + type = "lua"; + config = /* lua */ '' + -- local luasnip = require 'luasnip' + local cmp = require 'cmp' + + cmp.setup { + -- snippet = { + -- expand = function(args) + -- require('luasnip').lsp_expand(args.body) + -- end, + -- }, + window = { + -- documentation = true, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, + [''] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, + }), + sources = { + { name = 'nvim_lsp' }, + -- { name = 'luasnip' }, + { name = 'buffer' }, + { name = 'path' }, + -- { name = 'latex_symbols' }, + }, + } + ''; + } + { + plugin = nvim-lspconfig; + type = "lua"; + config = /* lua */ '' + function hi(name, opts) + local options = "" + for k, v in pairs(opts) do + options = options.." "..k.."="..v + end + vim.cmd("highlight "..name..options) + end + + local u = require('utils') + local lspc = require('lspconfig') + local ih = require("inlay-hints") + ih.setup() + + + 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 + + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + local opts = { noremap=true, silent=true } + + buf_set_keymap('n', '', ':lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gD', ':lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', ':lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', '1gD', ':lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'gr', ':lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'g0', ':lua vim.lsp.buf.document_symbol()', opts) + buf_set_keymap('n', 'gW', ':lua vim.lsp.buf.workspace_symbol()', opts) + buf_set_keymap('n', 'gd', ':lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'ga', ':lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'ff', ':lua vim.lsp.buf.format({async = true})', opts) + buf_set_keymap('n', 'gn', 'lua vim.lsp.buf.rename()', opts) + + --require'completion'.on_attach(client) + + -- Set highlight colors + local highlights = { + Error = "Red", + Warning = "Yellow", + Information = "Blue", + Hint = "Green", + } + + for typ, color in pairs(highlights) do + hi('LspDiagnosticsDefault'..typ, {ctermfg = color}) + hi('LspDiagnosticsUnderline'..typ, {cterm = 'underline'}) + end + + vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, + { + virtual_text = true, + signs = true, + update_in_insert = true, + underline = true + } + ) + require "lsp_signature".on_attach({doc_lines = 0}) + ih.on_attach(client, bufnr) + end + + -- nvim-cmp supports additional completion capabilities + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + + + local config = { + on_attach = on_attach, + capabilities = capabilities, + flags = {debounce_text_changes = 150} + } + + lspc.bashls.setup(config) + lspc.nixd.setup(config) + lspc.solargraph.setup(config) + + lspc.rust_analyzer.setup{ + on_attach = on_attach, + capabilities = capabilities, + flags = {debounce_text_changes = 150}, + settings = { + ['rust-analyzer'] = { + assist = { + importGranularity = "module", + importPrefix = "by_self", + }, + cargo = { + loadOutDirsFromCheck = true + }, + procMacro = { + enable = true + }, + checkOnSave = { + command = "clippy" + }, + } + } + } + + -- Set completeopt to have a better completion experience + vim.o.completeopt = 'menuone,noselect' + ''; + } + ]; + + extraLuaConfig = /* lua */ '' + local onedark = require('onedark') + onedark.setup { style = 'warmer' } + onedark.load() + vim.cmd('set background=dark') + + local llc = require('lualine').get_config() + llc.options.theme = 'onedark' + require('lualine').setup(llc) + + local key = vim.api.nvim_set_keymap + local o = vim.o + local wo = vim.wo + local bo = vim.bo + local cmd = vim.cmd + + vim.cmd([[autocmd CursorHold * lua vim.diagnostic.open_float({focusable = false})]]) + + key('n', ';', ':Telescope find_files', {}) + key('n', '', ':NvimTreeToggle', {}) + key('n', 'gh', '/=expand("")N', {}) + + key('i', '', 'pumvisible() ? "" : ""', { expr = true, silent = true }) + key('i', '', 'pumvisible() ? "" : ""', { expr = true, silent = true }) + key('n', 'g', ':lua require"telescope.builtin".live_grep{}', {}) + key('v', 'c', ':w !wl-copy', { silent = true }) + + vim.api.nvim_exec( + [[ + augroup YankHighlight + autocmd! + autocmd TextYankPost * silent! lua vim.highlight.on_yank() + augroup end + ]] , + false + ) + + vim.api.nvim_create_autocmd("BufEnter", { + nested = true, + callback = function() + if #vim.api.nvim_list_wins() == 1 and vim.api.nvim_buf_get_name(0):match("NvimTree_") ~= nil then + vim.cmd 'quit' + end + end + }) + + cmd('syntax on') + cmd('set number') + cmd('set completeopt=menuone,noinsert,noselect') + cmd('set shortmess+=c') + cmd("autocmd CursorHold,CursorHoldI *.rs :lua require'lsp_extensions'.inlay_hints{ only_current_line = true }") + + o.startofline = true + wo.cursorline = true + + o.updatetime = 300 + wo.signcolumn='yes' + o.showcmd = true + + o.shell = 'bash' + o.mouse = 'a' + + o.smarttab = true + bo.tabstop = 2 + bo.shiftwidth = 2 + bo.expandtab = true + + wo.relativenumber = true + o.hidden = true + + ''; + + extraPackages = with pkgs; [ + shfmt + nixd + nodePackages.bash-language-server + ]; + }; +}