From 2ad4bee0f98370112bc1392ba637072f7eb5e4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Fri, 12 Jan 2024 18:08:11 +0100 Subject: [PATCH] vim: Split out --- hm/dev/c.nix | 2 +- hm/dev/common.nix | 13 +++ hm/gaming/default.nix | 1 + hm/vim/code.nix | 72 +++++++++++++++ hm/vim/decoration.nix | 49 +++++++++++ hm/vim/default.nix | 161 +--------------------------------- hm/vim/feline_test.vim | 9 -- hm/vim/lsp.nix | 72 +++++++++++++++ hm/vim/lsp_signature-nvim.lua | 3 - 9 files changed, 212 insertions(+), 170 deletions(-) create mode 100644 hm/vim/code.nix create mode 100644 hm/vim/decoration.nix delete mode 100644 hm/vim/feline_test.vim create mode 100644 hm/vim/lsp.nix delete mode 100644 hm/vim/lsp_signature-nvim.lua diff --git a/hm/dev/c.nix b/hm/dev/c.nix index fffdeae..43bd29d 100644 --- a/hm/dev/c.nix +++ b/hm/dev/c.nix @@ -28,7 +28,7 @@ programs.bash.shellAliases = { gdb = "gdb -x ${config.xdg.configHome}/gdbinit"; }; - programs.nixvim.extraPlugins = [ pkgs.vimPlugins.nvim-dap ]; # Debug Adapter Protocol client + programs.nixvim.plugins.dap.enable = true; # Debug Adapter Protocol client xdg.configFile = { "ccache.conf" = { text = "ccache_dir = ${config.xdg.cacheHome}/ccache"; diff --git a/hm/dev/common.nix b/hm/dev/common.nix index db41177..a434f7b 100644 --- a/hm/dev/common.nix +++ b/hm/dev/common.nix @@ -51,5 +51,18 @@ yosys gtkwave ]; + + programs.nixvim.plugins.lsp.servers = { + ansiblels.enable = config.frogeye.dev.ansible; # Ansible + bashls.enable = true; # Bash + jsonls.enable = true; # JSON + lua-ls.enable = true; # Lua (for Neovim debugging) + perlpls.enable = config.frogeye.dev.perl; # Perl + phpactor.enable = config.frogeye.dev.php; # PHP + rnix-lsp.enable = true; # Nix + # TODO Something for SQL. sqls is deprecated, sqlls is not in Nixpkgs. Probably needs a DB connection configured anyways? + yamlls.enable = true; # YAML + # TODO Check out none-ls + }; }; } diff --git a/hm/gaming/default.nix b/hm/gaming/default.nix index b45f283..0598e89 100644 --- a/hm/gaming/default.nix +++ b/hm/gaming/default.nix @@ -11,6 +11,7 @@ # TODO factorio steam # Common pitfall: https://github.com/NixOS/nixpkgs/issues/86506#issuecomment-623746883 + itch ]; sessionVariables = { BOOT9_PATH = "${config.xdg.dataHome}/citra-emu/sysdata/boot9.bin"; diff --git a/hm/vim/code.nix b/hm/vim/code.nix new file mode 100644 index 0000000..e577957 --- /dev/null +++ b/hm/vim/code.nix @@ -0,0 +1,72 @@ +{ pkgs, lib, config, ... }: +let + # UPST + vim-shot-f = pkgs.vimUtils.buildVimPlugin { + pname = "vim-shot-f"; + version = "2016-02-05"; + src = pkgs.fetchFromGitHub { + owner = "deris"; + repo = "vim-shot-f"; + rev = "eea71d2a1038aa87fe175de9150b39dc155e5e7f"; + sha256 = "iAPvIs/lhW+w5kFTZKaY97D/kfCGtqKrJVFvZ8cHu+c="; + }; + meta.homepage = "https://github.com/deris/vim-shot-f"; + }; + quick-scope = pkgs.vimUtils.buildVimPlugin rec { + pname = "quick-scope"; + version = "2.6.1"; + src = pkgs.fetchFromGitHub { + owner = "unblevable"; + repo = "quick-scope"; + rev = "v${version}"; + sha256 = "TcA4jZIdnQd06V+JrXGiCMr0Yhm9gB6OMiTSdzMt/Qw="; + }; + meta.homepage = "https://github.com/unblevable/quick-scope"; + }; +in +{ + config = { + programs.nixvim = { + extraPlugins = with pkgs.vimPlugins; [ + # f/F mode + vim-shot-f # Highlight relevant characters for f/F/t/T modes + quick-scope # Highlight relevant characters for f/F modes one per word but always + ]; + options = { + # From https://www.hillelwayne.com/post/intermediate-vim/ + scrolloff = 10; + lazyredraw = true; # Do not redraw screen in the middle of a macro. Makes them complete faster. + cursorcolumn = true; + + # From http://stackoverflow.com/a/5004785/2766106 + list = true; + listchars = "tab:╾╌,trail:·,extends:↦,precedes:↤,nbsp:_"; + showbreak = "↪"; + }; + plugins = { + # Catches attention when cursor changed position + specs = { + enable = true; + min_jump = 5; + fader = { builtin = "pulse_fader"; }; + resizer = { builtin = "shrink_resizer"; }; + }; + + # Treesitter + treesitter = { + # Allows for better syntax highlighting + enable = true; + incrementalSelection = { + enable = true; + }; + # indent = true; # Not very working last time I tried apparently + }; + # TODO Investigate https://github.com/nvim-treesitter/nvim-treesitter-textobjects + indent-blankline.enable = true; # Show indent guides + rainbow-delimiters.enable = true; # Randomly colore paired brackets + + nvim-colorizer.enable = true; # Display colors of color-codes + }; + }; + }; +} diff --git a/hm/vim/decoration.nix b/hm/vim/decoration.nix new file mode 100644 index 0000000..6dc2d47 --- /dev/null +++ b/hm/vim/decoration.nix @@ -0,0 +1,49 @@ +{ pkgs, lib, config, ... }: +{ + config = { + programs.nixvim = { + autoCmd = [ + # Turn off relativenumber only for insert mode + { event = "InsertEnter"; pattern = "*"; command = "set norelativenumber"; } + { event = "InsertLeave"; pattern = "*"; command = "set relativenumber"; } + ]; + extraConfigLua = builtins.readFile ./feline.lua; + extraPlugins = with pkgs.vimPlugins; [ + nvim-scrollview # Scroll bar + # Status line + feline-nvim # Customizable status line. + # TODO Abandonned. Maybe use lualine? + ]; + keymaps = [ + # barbar + { key = ""; action = "BufferPrevious"; options = { silent = true; }; } + { key = ""; action = "BufferNext"; options = { silent = true; }; } + # TODO https://www.reddit.com/r/neovim/comments/mbj8m5/how_to_setup_ctrlshiftkey_mappings_in_neovim_and/ + { key = ""; action = "BufferMovePrevious"; options = { silent = true; }; } + { key = ""; action = "BufferMoveNext"; options = { silent = true; }; } + # TODO gotos don't work + { key = ""; action = "BufferGoto 1"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 2"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 3"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 4"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 5"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 6"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 7"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 8"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 9"; options = { silent = true; }; } + { key = ""; action = "BufferLast"; options = { silent = true; }; } + { key = "gb"; action = "BufferPick"; options = { silent = true; }; } + # TODO Other useful options? + ]; + options = { + title = true; + number = true; + relativenumber = true; + }; + plugins = { + # Tabline + barbar.enable = true; + }; + }; + }; +} diff --git a/hm/vim/default.nix b/hm/vim/default.nix index 0836392..1ac8b81 100644 --- a/hm/vim/default.nix +++ b/hm/vim/default.nix @@ -1,29 +1,4 @@ { pkgs, lib, config, ... }: -let - # UPST - vim-shot-f = pkgs.vimUtils.buildVimPlugin { - pname = "vim-shot-f"; - version = "2016-02-05"; - src = pkgs.fetchFromGitHub { - owner = "deris"; - repo = "vim-shot-f"; - rev = "eea71d2a1038aa87fe175de9150b39dc155e5e7f"; - sha256 = "iAPvIs/lhW+w5kFTZKaY97D/kfCGtqKrJVFvZ8cHu+c="; - }; - meta.homepage = "https://github.com/deris/vim-shot-f"; - }; - quick-scope = pkgs.vimUtils.buildVimPlugin rec { - pname = "quick-scope"; - version = "2.6.1"; - src = pkgs.fetchFromGitHub { - owner = "unblevable"; - repo = "quick-scope"; - rev = "v${version}"; - sha256 = "TcA4jZIdnQd06V+JrXGiCMr0Yhm9gB6OMiTSdzMt/Qw="; - }; - meta.homepage = "https://github.com/unblevable/quick-scope"; - }; -in { # config = lib.mkIf config.programs.nixvim.enable { # Somehow this is infinite recursion? config = { @@ -42,14 +17,6 @@ in # polarity. colorschemes.base16.colorscheme = "solarized-${config.frogeye.polarity}"; options = { - # From https://www.hillelwayne.com/post/intermediate-vim/ - title = true; - number = true; - relativenumber = true; - scrolloff = 10; - lazyredraw = true; # Do not redraw screen in the middle of a macro. Makes them complete faster. - cursorcolumn = true; - ignorecase = true; smartcase = true; gdefault = true; @@ -64,11 +31,6 @@ in updatetime = 250; undofile = true; - # From http://stackoverflow.com/a/5004785/2766106 - list = true; - listchars = "tab:╾╌,trail:·,extends:↦,precedes:↤,nbsp:_"; - showbreak = "↪"; - wildmode = "longest:full,full"; wildmenu = true; }; @@ -76,19 +38,6 @@ in netrw_fastbrowse = 0; # Close the file explorer once you select a file }; plugins = { - # Catches attention when cursor changed position - # TODO Unmapped, do I still want to use it? - specs = { - enable = true; - min_jump = 5; - fader = { builtin = "pulse_fader"; }; - resizer = { builtin = "shrink_resizer"; }; - }; - - # Tabline - barbar.enable = true; - - # Go to whatever telescope = { enable = true; @@ -136,84 +85,14 @@ in # Surrounding pairs surround.enable = true; # Change surrounding pairs (e.g. brackets, quotes) - # Language Server - lsp = { - enable = true; - keymaps = { - silent = true; - diagnostic = { - "e" = "open_float"; - "[e" = "goto_prev"; - "]e" = "goto_next"; - }; - lspBuf = { - "gD" = "declaration"; - "K" = "hover"; - "gi" = "implementation"; - "" = "signature_help"; - "wa" = "add_workspace_folder"; - "wr" = "remove_workspace_folder"; - # "wl" = "list_workspace_folder"; - # TODO Full thing was function() print(vim.inspect(vim.lsp.buf.list_workspace_folder())) end but not sure I'm ever really using this - # Also makes nvim crash like this, so uncommented - "D" = "type_definition"; - "rn" = "rename"; - "f" = "format"; - # TODO Full thing was function() vim.lsp.buf.format { async = true } end, so async while this isn't - # Maybe replace this with lsp-format? - }; - }; - servers = { - ansiblels.enable = config.frogeye.dev.ansible; # Ansible - bashls.enable = true; # Bash - jsonls.enable = true; # JSON - lua-ls.enable = true; # Lua (for Neovim debugging) - perlpls.enable = config.frogeye.dev.perl; # Perl - phpactor.enable = config.frogeye.dev.php; # PHP - rnix-lsp.enable = true; # Nix - # TODO Something for SQL. sqls is deprecated, sqlls is not in Nixpkgs. Probably needs a DB connection configured anyways? - yamlls.enable = true; # YAML - # TODO Check out none-ls - }; - }; - nvim-lightbulb = { - # Shows a lightbulb whenever a codeAction is available under the cursor - enable = true; - autocmd.enabled = true; - }; - - # Treesitter - treesitter = { - # Allows for better syntax highlighting - enable = true; - incrementalSelection = { - enable = true; - }; - # indent = true; # Not very working last time I tried apparently - }; - # TODO Investigate https://github.com/nvim-treesitter/nvim-treesitter-textobjects - - rainbow-delimiters.enable = true; # Randomly colore paired brackets - - indent-blankline.enable = true; # Show indent guides - undotree.enable = true; # Navigate edition history # Git fugitive.enable = true; # Git basics gitsigns.enable = true; # Show changed lines in the gutter - # Language-specific - # dap.enable = true; # Debug Adapter Protocol client # 23.11 - nvim-colorizer.enable = true; # Display colors of color-codes }; extraPlugins = with pkgs.vimPlugins; [ - nvim-scrollview # Scroll bar - - # Status line - feline-nvim # Customizable status line. - # TODO Abandonned. Maybe use lualine? - # Search/replace vim-abolish # Regex for words, with case in mind vim-easy-align # Aligning lines around a certain character @@ -221,10 +100,6 @@ in # Surrounding pairs targets-vim # Better interaction with surrounding pairs - # f/F mode - vim-shot-f # Highlight relevant characters for f/F/t/T modes - quick-scope # Highlight relevant characters for f/F modes one per word but always - # Registers registers-nvim # Show register content when pressing " # TODO Doesn't work. Didn't work on Arch either @@ -234,9 +109,6 @@ in symbols-outline-nvim # Show a symbol panel on the right # TODO Fails on startup. Same on Arch. Config issue? - # Language server - lsp_signature-nvim # Show argument definition when typing a function - # Git fugitive-gitlab-vim # Open files in GitLab # TODO Connect it! @@ -251,11 +123,7 @@ in ] ++ lib.optionals config.frogeye.dev.ansible [ ansible-vim # TODO Doesn't have snippets ]; - extraConfigLua = lib.strings.concatMapStringsSep "\n" (f: builtins.readFile f) [ - ./feline.lua - ./symbols-outline-nvim.lua - ./lsp_signature-nvim.lua - ]; + extraConfigLua = builtins.readFile ./symbols-outline-nvim.lua; extraConfigVim = '' " GENERAL @@ -281,10 +149,6 @@ in ''; autoCmd = [ - # Turn off relativenumber only for insert mode - { event = "InsertEnter"; pattern = "*"; command = "set norelativenumber"; } - { event = "InsertLeave"; pattern = "*"; command = "set relativenumber"; } - # vim-easy-align: Align Markdown tables { event = "FileType"; pattern = "markdown"; command = "vmap :EasyAlign*"; } ]; @@ -315,26 +179,6 @@ in # PLUGINS - # barbar - { key = ""; action = "BufferPrevious"; options = { silent = true; }; } - { key = ""; action = "BufferNext"; options = { silent = true; }; } - # TODO https://www.reddit.com/r/neovim/comments/mbj8m5/how_to_setup_ctrlshiftkey_mappings_in_neovim_and/ - { key = ""; action = "BufferMovePrevious"; options = { silent = true; }; } - { key = ""; action = "BufferMoveNext"; options = { silent = true; }; } - # TODO gotos don't work - { key = ""; action = "BufferGoto 1"; options = { silent = true; }; } - { key = ""; action = "BufferGoto 2"; options = { silent = true; }; } - { key = ""; action = "BufferGoto 3"; options = { silent = true; }; } - { key = ""; action = "BufferGoto 4"; options = { silent = true; }; } - { key = ""; action = "BufferGoto 5"; options = { silent = true; }; } - { key = ""; action = "BufferGoto 6"; options = { silent = true; }; } - { key = ""; action = "BufferGoto 7"; options = { silent = true; }; } - { key = ""; action = "BufferGoto 8"; options = { silent = true; }; } - { key = ""; action = "BufferGoto 9"; options = { silent = true; }; } - { key = ""; action = "BufferLast"; options = { silent = true; }; } - { key = "gb"; action = "BufferPick"; options = { silent = true; }; } - # TODO Other useful options? - # symbols-outline-nvim { key = "s"; action = "SymbolsOutline"; options = { silent = true; }; } @@ -346,6 +190,9 @@ in }; imports = [ + ./code.nix ./completion.nix + ./decoration.nix + ./lsp.nix ]; } diff --git a/hm/vim/feline_test.vim b/hm/vim/feline_test.vim deleted file mode 100644 index 7ddb1cd..0000000 --- a/hm/vim/feline_test.vim +++ /dev/null @@ -1,9 +0,0 @@ -source ~/.config/vim/plug.vim -call plug#begin('~/.cache/nvim/plugged') -Plug 'RRethy/nvim-base16' -call plug#end() - -colorscheme base16-solarized-dark -lua << EOF -a = require('base16-colorscheme').colors.base00 -EOF diff --git a/hm/vim/lsp.nix b/hm/vim/lsp.nix new file mode 100644 index 0000000..a1c085f --- /dev/null +++ b/hm/vim/lsp.nix @@ -0,0 +1,72 @@ +{ pkgs, lib, config, ... }: +{ + config = { + programs.nixvim = { + extraConfigLua = '' + require'lsp_signature'.on_attach({ + hint_enable = false, + }) + ''; + extraPlugins = with pkgs.vimPlugins; [ + # Language server + lsp_signature-nvim # Show argument definition when typing a function + ]; + keymaps = [ + # barbar + { key = ""; action = "BufferPrevious"; options = { silent = true; }; } + { key = ""; action = "BufferNext"; options = { silent = true; }; } + # TODO https://www.reddit.com/r/neovim/comments/mbj8m5/how_to_setup_ctrlshiftkey_mappings_in_neovim_and/ + { key = ""; action = "BufferMovePrevious"; options = { silent = true; }; } + { key = ""; action = "BufferMoveNext"; options = { silent = true; }; } + # TODO gotos don't work + { key = ""; action = "BufferGoto 1"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 2"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 3"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 4"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 5"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 6"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 7"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 8"; options = { silent = true; }; } + { key = ""; action = "BufferGoto 9"; options = { silent = true; }; } + { key = ""; action = "BufferLast"; options = { silent = true; }; } + { key = "gb"; action = "BufferPick"; options = { silent = true; }; } + # TODO Other useful options? + ]; + plugins = { + # Language Server + lsp = { + enable = true; + keymaps = { + silent = true; + diagnostic = { + "e" = "open_float"; + "[e" = "goto_prev"; + "]e" = "goto_next"; + }; + lspBuf = { + "gD" = "declaration"; + "K" = "hover"; + "gi" = "implementation"; + "" = "signature_help"; + "wa" = "add_workspace_folder"; + "wr" = "remove_workspace_folder"; + # "wl" = "list_workspace_folder"; + # TODO Full thing was function() print(vim.inspect(vim.lsp.buf.list_workspace_folder())) end but not sure I'm ever really using this + # Also makes nvim crash like this, so uncommented + "D" = "type_definition"; + "rn" = "rename"; + "f" = "format"; + # TODO Full thing was function() vim.lsp.buf.format { async = true } end, so async while this isn't + # Maybe replace this with lsp-format? + }; + }; + }; + nvim-lightbulb = { + # Shows a lightbulb whenever a codeAction is available under the cursor + enable = true; + autocmd.enabled = true; + }; + }; + }; + }; +} diff --git a/hm/vim/lsp_signature-nvim.lua b/hm/vim/lsp_signature-nvim.lua deleted file mode 100644 index 4f5fff7..0000000 --- a/hm/vim/lsp_signature-nvim.lua +++ /dev/null @@ -1,3 +0,0 @@ -require'lsp_signature'.on_attach({ - hint_enable = false, -})