From a70015bd2cf8141c21fc8ee38f605b2f80aed32c Mon Sep 17 00:00:00 2001 From: oddlama Date: Thu, 23 Nov 2023 03:03:00 +0100 Subject: [PATCH] feat(neovim): wip: add most of the missing plugins --- users/myuser/neovim/default.nix | 255 +++++++++++++++++++++++++------- 1 file changed, 200 insertions(+), 55 deletions(-) diff --git a/users/myuser/neovim/default.nix b/users/myuser/neovim/default.nix index 6b288bb..4e62b5c 100644 --- a/users/myuser/neovim/default.nix +++ b/users/myuser/neovim/default.nix @@ -1,16 +1,22 @@ # TODO whichkey +# TODO vim illuminate # TODO alpha menu # TODO keybinds -# TODO window select +# TODO dap dapui # TODO neotree left darker # TODO neotree focsed shows lualine wrongly (full instead of nothing) # TODO lualine inactive ------ is ugly +# TODO move lines. gomove again? +# TODO vim-wordmotion vs https://github.com/chrisgrieser/nvim-various-textobjs +# TODO blankline cur indent too bright { lib, pkgs, ... }: { + # TODO use programs.nixvim? and split stuff a little. home.shellAliases.nixvim = lib.getExe (pkgs.nixvim.makeNixvim { + # TODO away once we are ready to switch (prevents shada and undohist currently) package = pkgs.neovim-clean; # TODO for wayland: @@ -31,6 +37,7 @@ }; }; + luaLoader.enable = true; globals.mapleader = ","; # Hide line numbers in terminal windows @@ -38,13 +45,26 @@ { event = ["BufEnter" "BufWinEnter"]; pattern = ["term://*"]; - callback = { - __raw = '' - function() - vim.bo.number = false - end - ''; - }; + callback.__raw = '' + function() + vim.bo.number = false + end + ''; + } + { + event = ["WinEnter"]; + pattern = ["*"]; + callback.__raw = '' + function() + pcall(function() + if vim.bo.buftype == "nofile" or vim.bo.buftype == "help" then + vim.cmd "DisableWhitespace" + else + vim.cmd "EnableWhitespace" + end + end) + end + ''; } ]; @@ -112,23 +132,134 @@ }; keymaps = let - withDefaults = lib.recursiveUpdate { + keymap = mode: key: action: desc: { + inherit action key mode; options = { silent = true; - noremap = true; + inherit desc; }; }; - in - map withDefaults [ - { - action = ""; - key = ""; - mode = ["n"]; - options.desc = "Jump to tag under cursor"; - } - ]; + in [ + # ------------------------------------------------------------------------------------------------- + # General + # ------------------------------------------------------------------------------------------------- + + # Shift + scroll with cursor locked to position + (keymap ["n" "v"] "" "" "") + (keymap ["n" "v"] "" "" "") + (keymap ["i"] "" "" "") + (keymap ["i"] "" "" "") + + # Shift + Alt + change the current window size + (keymap ["n"] "" ":resize -2" "") + (keymap ["n"] "" ":resize +2" "") + (keymap ["n"] "" ":vertical resize -2" "") + (keymap ["n"] "" ":vertical resize +2" "") + + # Allow exiting terminal mode + (keymap ["t"] "" "" "") + # Allow C-w in terminal mode + (keymap ["t"] "" "" "") + + # Open fixed size terminal window at the bottom + (keymap ["n"] "" ":belowright new | setlocal wfh | resize 10 | terminal" "") + + # ------------------------------------------------------------------------------------------------- + # Language server + # ------------------------------------------------------------------------------------------------- + + (keymap ["n"] "gD" "lua vim.lsp.buf.declaration()" "") + (keymap ["n"] "gd" "lua require('telescope.builtin').lsp_definitions()" "") + (keymap ["n"] "K" "lua vim.lsp.buf.hover()" "") + (keymap ["n"] "gi" "lua require('telescope.builtin').lsp_implementations()" "") + (keymap ["n"] "" "lua vim.lsp.buf.signature_help()" "") + (keymap ["n"] "wa" "lua vim.lsp.buf.add_workspace_folder()" "") + (keymap ["n"] "wr" "lua vim.lsp.buf.remove_workspace_folder()" "") + (keymap ["n"] "wl" "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))" "") + (keymap ["n"] "gt" "lua require('telescope.builtin').lsp_type_definitions()" "") + (keymap ["n"] "r" "lua vim.lsp.buf.rename()" "") + (keymap ["n"] "a" "lua vim.lsp.buf.code_action()" "") + (keymap ["n"] "gr" "lua require('telescope.builtin').lsp_references()" "") + (keymap ["n"] "gl" "lua vim.diagnostic.open_float()" "") + (keymap ["n"] "[d" "lua vim.diagnostic.goto_prev()" "") + (keymap ["n"] "]d" "lua vim.diagnostic.goto_next()" "") + (keymap ["n"] "q" "lua vim.diagnostic.setloclist()" "") + (keymap ["n"] "f" "lua vim.lsp.buf.format { async = true }" "") + + # ------------------------------------------------------------------------------------------------- + # Plugin: Easy Align + # ------------------------------------------------------------------------------------------------- + + (keymap ["n"] "A" "(EasyAlign)" "") + (keymap ["v"] "A" "(EasyAlign)" "") + + # ------------------------------------------------------------------------------------------------- + # Plugin: Undotree + # ------------------------------------------------------------------------------------------------- + + (keymap ["n"] "u" ":UndotreeToggle" "") + + # ------------------------------------------------------------------------------------------------- + # Plugin: Better Whitespace + # ------------------------------------------------------------------------------------------------- + + (keymap ["n"] "$" ":StripWhitespace" "") + + # ------------------------------------------------------------------------------------------------- + # Plugin: Neotree + # ------------------------------------------------------------------------------------------------- + + # Mappings to open the tree / find the current file + (keymap ["n"] "t" ":Neotree toggle" "") + (keymap ["n"] "T" ":Neotree reveal" "") + (keymap ["n"] "G" ":Neotree float git_status" "") + (keymap ["n"] "b" ":Neotree float buffers" "") + + # ------------------------------------------------------------------------------------------------- + # Plugin: Sandwich + # ------------------------------------------------------------------------------------------------- + + (keymap ["n" "v"] "m" "(operator-sandwich-add)" "") + (keymap ["n" "v"] "M" "(operator-sandwich-delete)" "") + (keymap ["n" "v"] "C-m" "(operator-sandwich-replace)" "") + + # ------------------------------------------------------------------------------------------------- + # Plugin: gomove + # ------------------------------------------------------------------------------------------------- + + #(keymap ["n"] "" "GoNSMLeft" "") + #(keymap ["n"] "" "GoNSMDown" "") + #(keymap ["n"] "" "GoNSMUp" "") + #(keymap ["n"] "" "GoNSMRight" "") + + (keymap ["x"] "" "GoVSMLeft" "") + (keymap ["x"] "" "GoVSMDown" "") + (keymap ["x"] "" "GoVSMUp" "") + (keymap ["x"] "" "GoVSMRight" "") + + #(keymap ["n"] "" "GoNSDLeft" "") + #(keymap ["n"] "" "GoNSDDown" "") + #(keymap ["n"] "" "GoNSDUp" "") + #(keymap ["n"] "" "GoNSDRight" "") + + (keymap ["x"] "" "GoVSDLeft" "") + (keymap ["x"] "" "GoVSDDown" "") + (keymap ["x"] "" "GoVSDUp" "") + (keymap ["x"] "" "GoVSDRight" "") + + # ------------------------------------------------------------------------------------------------- + # Plugin: wordmotion + # ------------------------------------------------------------------------------------------------- + + (keymap ["x" "o"] "ie" "WordMotion_iw" "") + + # ------------------------------------------------------------------------------------------------- + # Plugin: textcase + # ------------------------------------------------------------------------------------------------- + + # TODO: ... keybinds + telescope integration + ]; - luaLoader.enable = true; plugins = { # ------------------------------------------------------------------------------------------------- # Library plugins @@ -181,18 +312,11 @@ # Line indentation markers indent-blankline.enable = true; - # Show invalid whitespace - # TODO use { "ntpeters/vim-better-whitespace", config = conf_fn "better-whitespace" } - # Rainbow parentheses rainbow-delimiters.enable = true; - # Replace built-in LSP prompts and windows - # TODO use { "stevearc/dressing.nvim", config = conf_setup "dressing" } # Status updates for LSP progress in right bottom corner. fidget.enable = true; - # Show latex math equations - # TODO use { "jbyuki/nabla.nvim", config = conf_fn "nabla" } # Show colors nvim-colorizer.enable = true; @@ -205,7 +329,7 @@ treesitter = { enable = true; - folding = true; + # TODO (autocmd * zR needed) folding = true; indent = true; incrementalSelection = { @@ -242,24 +366,10 @@ # Editing # ------------------------------------------------------------------------------------------------- - # Multicursor - # TODO use { "mg979/vim-visual-multi" } # Commenting comment-nvim.enable = true; - # Modify Surrounding things like parenthesis and quotes - # TODO use { "machakann/vim-sandwich", config = conf_fn "sandwich" } # Extend vim's "%" key vim-matchup.enable = true; - # Align - # TODO use "junegunn/vim-easy-align" - # Move blocks - # TODO use { "booperlv/nvim-gomove", config = conf_setup "gomove" } - # Case changer - # TODO use "johmsalas/text-case.nvim" - # camelcase (and similar) word motions and textobjects - # TODO use { "chaoren/vim-wordmotion", config = conf_fn "wordmotion" } - # Respect editor-config files - # TODO use { "gpanders/editorconfig.nvim" } # ---------------------------------------------------------------------------------------------------- # Functionality @@ -273,9 +383,8 @@ }; # Startup screen - # TODO use { "goolord/alpha-nvim", config = conf_module "alpha" } - # Window Picker - # TODO use { "s1n7ax/nvim-window-picker", tag = "v1.*", config = conf_setup "window-picker" } + alpha.enable = true; + # Filebrowser neo-tree = { enable = true; @@ -338,9 +447,6 @@ windowLayout = 4; }; - # Gpg integration - # TODO use "jamessan/vim-gnupg" - # ------------------------------------------------------------------------------------------------- # Git # ------------------------------------------------------------------------------------------------- @@ -351,14 +457,14 @@ # Git commands fugitive.enable = true; + diffview.enable = true; + # Manage git from within neovim neogit = { enable = true; disableBuiltinNotifications = true; }; - diffview.enable = true; - # ------------------------------------------------------------------------------------------------- # Completion # ------------------------------------------------------------------------------------------------- @@ -554,7 +660,7 @@ Table = "", Object = "󰅩", Tag = "", - Array = "[]", + Array = "󰅪", Boolean = "", Number = "", Null = "󰟢", @@ -581,20 +687,45 @@ # Miscellaneous # ------------------------------------------------------------------------------------------------- - # TODO use { "folke/trouble.nvim", config = conf_setup "trouble" } # Quickfix menu trouble.enable = true; # Highlight certain keywords todo-comments.enable = true; # TODO use { "liuchengxu/vista.vim", cmd = "Vista" } + which-key.enable = true; }; extraPlugins = with pkgs.vimPlugins; [ + telescope-ui-select-nvim nvim-web-devicons nvim-window-picker - telescope-ui-select-nvim + # Replace built-in LSP prompts and windows + dressing-nvim + # Multicursor + vim-visual-multi + # Show invalid whitespace + vim-better-whitespace + # Show latex math equations + nabla-nvim + # Modify Surrounding things like parenthesis and quotes + vim-sandwich + # TODO mini.align better? + vim-easy-align + # Case changer + text-case-nvim + # camelcase (and similar) word motions and textobjects + vim-wordmotion + # Gpg integration + vim-gnupg ]; + extraConfigLuaPre = '' + vim.g.operator_sandwich_no_default_key_mappings = 1 + vim.g.textobj_sandwich_no_default_key_mappings = 1 + + vim.g.wordmotion_nomap = 1 + ''; + extraConfigLuaPost = '' require("nvim-web-devicons").setup { override = { @@ -642,14 +773,28 @@ require("window-picker").setup { hint = "floating-big-letter", - selection_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", filter_rules = { bo = { filetype = { "neo-tree", "neo-tree-popup", "notify", "quickfix" }, buftype = { "terminal", "quickfix", "prompt" }, }, }, - other_win_hl_color = "#4493c8", + floating_big_letter = { + font = "ansi-shadow", + }, + selection_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + show_prompt = false, + } + + require("dressing").setup { + input = { + prefer_width = 80, + max_width = { 140, 0.9 }, + min_width = { 80, 0.6 }, + win_options = { + winblend = 0, + }, + }, } ''; });