From 424fba524c746f948e31e118d570b9163c4b5100 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 22 Feb 2023 15:19:04 +0900 Subject: [PATCH] Add motions to vim --- modules/home/apps/default.nix | 1 - modules/home/nvim/default.nix | 9 ++- modules/home/nvim/lazy-lock.json | 14 ++++- .../plugins/{settings.lua => colorscheme.lua} | 6 +- modules/home/nvim/lua/plugins/git.lua | 36 ++++++++++++ modules/home/nvim/lua/plugins/motions.lua | 57 +++++++++++++++++++ modules/home/nvim/lua/plugins/telescope.lua | 2 +- modules/home/nvim/lua/plugins/treesiter.lua | 37 ++++++++++++ modules/home/nvim/lua/plugins/ui.lua | 53 ++++++++++++++++- 9 files changed, 201 insertions(+), 14 deletions(-) rename modules/home/nvim/lua/plugins/{settings.lua => colorscheme.lua} (70%) create mode 100644 modules/home/nvim/lua/plugins/git.lua create mode 100644 modules/home/nvim/lua/plugins/motions.lua create mode 100644 modules/home/nvim/lua/plugins/treesiter.lua diff --git a/modules/home/apps/default.nix b/modules/home/apps/default.nix index aeea5d7..d79d294 100644 --- a/modules/home/apps/default.nix +++ b/modules/home/apps/default.nix @@ -21,7 +21,6 @@ in { config = mkIf cfg.enable { home.packages = with pkgs; [ - neovim google-chrome firefox mpv diff --git a/modules/home/nvim/default.nix b/modules/home/nvim/default.nix index 03a27b2..36522df 100644 --- a/modules/home/nvim/default.nix +++ b/modules/home/nvim/default.nix @@ -11,6 +11,13 @@ in { config = lib.mkIf cfg.enable { home.packages = with pkgs; [neovim]; - xdg.configFile."nvim".source = ./.; + xdg.configFile."nvim/lua".source = ./lua; + xdg.configFile."nvim/lazy-lock.json".source = ./lazy-lock.json; + xdg.configFile."nvim/init.lua".text = '' + -- Nix + vim.env.CC = "${pkgs.gcc}/bin/gcc" + + ${builtins.readFile ./init.lua} + ''; }; } diff --git a/modules/home/nvim/lazy-lock.json b/modules/home/nvim/lazy-lock.json index aa1d57c..914a834 100644 --- a/modules/home/nvim/lazy-lock.json +++ b/modules/home/nvim/lazy-lock.json @@ -1,19 +1,27 @@ { - "catppuccin": { "branch": "main", "commit": "fe32c776d86e8ba608e6294c43302c985835bfea" }, + "catppuccin": { "branch": "main", "commit": "4175759297350557315987d479fb687a9f0b781f" }, + "dressing.nvim": { "branch": "master", "commit": "db716a0f1279f79a886c0e0b6ab3c3d5ffdb42fe" }, + "gitsigns.nvim": { "branch": "main", "commit": "f388995990aba04cfdc7c3ab870c33e280601109" }, + "harpoon": { "branch": "master", "commit": "8faeac2b91e2d0f1a27cae992340a791cbdc2da8" }, "increment-activator": { "branch": "master", "commit": "55efcff88be45bd98cfdf7333dd718399373d10c" }, "indent-blankline.nvim": { "branch": "master", "commit": "018bd04d80c9a73d399c1061fa0c3b14a7614399" }, "lazy.nvim": { "branch": "main", "commit": "8077428e63feb0f3bf795d53b23ba1695b28ab0e" }, + "leap.nvim": { "branch": "main", "commit": "9a69febb2e5a4f5f5a55dd2d7173098fde917bc5" }, "lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" }, "neo-tree.nvim": { "branch": "v2.x", "commit": "245cf1e68840defcc75a16297740f6203f5a045d" }, "noice.nvim": { "branch": "main", "commit": "d8a1f3056ad713b5d471048f8d029264828e22c0" }, "nui.nvim": { "branch": "main", "commit": "d147222a1300901656f3ebd5b95f91732785a329" }, - "nvim-lspconfig": { "branch": "master", "commit": "b5db147e28337319331d516a826b00976f3584de" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "550332c5791c6cad6fc7a80c26104de1d00b4692" }, + "nvim-lspconfig": { "branch": "master", "commit": "91998cef4b1ae3a624901d0f9c894409db24e760" }, "nvim-navic": { "branch": "master", "commit": "7e9d2b2b601149fecdccd11b516acb721e571fe6" }, "nvim-scrollbar": { "branch": "main", "commit": "75210c554e935740448cfb532d8a671ae544bb1b" }, + "nvim-treesitter": { "branch": "master", "commit": "ce0dba96f47cd8bbd46b4c3ac8fd1b9502f1002a" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "2f3583001e2bf793480f38cf0d055571787b0259" }, "nvim-web-devicons": { "branch": "master", "commit": "4709a504d2cd2680fb511675e64ef2790d491d36" }, "plenary.nvim": { "branch": "master", "commit": "253d34830709d690f013daf2853a9d21ad7accab" }, "telescope-fzf-native.nvim": { "branch": "feature/69-prebuilt-release-binaries", "commit": "6388c4f4ec5eab8b89f974a9fa57fc955a67bbb2" }, - "telescope.nvim": { "branch": "master", "commit": "f40e3e2304c633411ddf266075f7db5184b1db02" }, + "telescope.nvim": { "branch": "master", "commit": "a486ac3e8fb2198f3636da1927ed57a28836fbd8" }, + "unimpaired-which-key.nvim": { "branch": "main", "commit": "321a247ecbbb31a59a8580350eec044b88d82e81" }, "vim-repeat": { "branch": "master", "commit": "24afe922e6a05891756ecf331f39a1f6743d3d5a" }, "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" }, "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" }, diff --git a/modules/home/nvim/lua/plugins/settings.lua b/modules/home/nvim/lua/plugins/colorscheme.lua similarity index 70% rename from modules/home/nvim/lua/plugins/settings.lua rename to modules/home/nvim/lua/plugins/colorscheme.lua index 4688f16..0389485 100644 --- a/modules/home/nvim/lua/plugins/settings.lua +++ b/modules/home/nvim/lua/plugins/colorscheme.lua @@ -14,6 +14,7 @@ return { neotree = true, noice = true, mini = true, + leap = true, harpoon = true, gitsigns = true, semantic_tokens = true, @@ -25,9 +26,4 @@ return { vim.cmd([[colorscheme catppuccin-mocha]]) end }, - "tpope/vim-surround", - "tpope/vim-sleuth", - { "tpope/vim-repeat", event = "VeryLazy" }, - { "tpope/vim-unimpaired", config = function() vim.g.nremap = { ["[u"] = "", ["]u"] = "" } end }, - "nishigori/increment-activator", } diff --git a/modules/home/nvim/lua/plugins/git.lua b/modules/home/nvim/lua/plugins/git.lua new file mode 100644 index 0000000..3ddea65 --- /dev/null +++ b/modules/home/nvim/lua/plugins/git.lua @@ -0,0 +1,36 @@ +return { + { + "lewis6991/gitsigns.nvim", + event = { "BufReadPre", "BufNewFile" }, + opts = { + signs = { + add = { text = "▎" }, + change = { text = "▎" }, + delete = { text = "契" }, + topdelete = { text = "契" }, + changedelete = { text = "▎" }, + untracked = { text = "▎" }, + }, + on_attach = function(buffer) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, desc) + vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc }) + end + + map("n", "]h", gs.next_hunk, "Next Hunk") + map("n", "[h", gs.prev_hunk, "Prev Hunk") + map({ "n", "v" }, "ghs", ":Gitsigns stage_hunk", "Stage Hunk") + map({ "n", "v" }, "ghr", ":Gitsigns reset_hunk", "Reset Hunk") + map("n", "ga", gs.stage_buffer, "Add buffer") + map("n", "gr", gs.undo_stage_hunk, "Remove buffer (unstage)") + map("n", "gR", gs.reset_buffer, "Reset Buffer") + map("n", "gp", gs.preview_hunk, "Preview Hunk") + map("n", "gb", function() gs.blame_line({ full = true }) end, "Blame Line") + map("n", "gd", gs.diffthis, "Diff This") + map("n", "gD", function() gs.diffthis("~") end, "Diff This ~") + map({ "o", "x" }, "ih", ":Gitsigns select_hunk", "Git Select Hunk") + end, + }, + }, +} diff --git a/modules/home/nvim/lua/plugins/motions.lua b/modules/home/nvim/lua/plugins/motions.lua new file mode 100644 index 0000000..8129679 --- /dev/null +++ b/modules/home/nvim/lua/plugins/motions.lua @@ -0,0 +1,57 @@ +return { + { + "ggandor/leap.nvim", + keys = { + { "s", mode = { "n", "x", "o" }, desc = "Leap forward to" }, + { "S", mode = { "n", "x", "o" }, desc = "Leap backward to" }, + { "gs", mode = { "n", "x", "o" }, desc = "Leap from windows" }, + }, + config = function(_, opts) + local leap = require("leap") + for k, v in pairs(opts) do + leap.opts[k] = v + end + leap.add_default_mappings(true) + vim.keymap.del({ "x", "o" }, "x") + vim.keymap.del({ "x", "o" }, "X") + end, + }, + { "tpope/vim-repeat", event = "VeryLazy" }, + + { + "ThePrimeagen/harpoon", + keys = { + { "a", 'lua require("harpoon.mark").add_file()', desc = "Mark file" }, + { "h", 'lua require("harpoon.ui").toggle_quick_menu()', desc = "Harpoon menu" }, + + { "", 'lua require("harpoon.ui").nav_file(1)', desc = "Navigate to harpoon 1" }, + { "", 'lua require("harpoon.ui").nav_file(2)', desc = "Navigate to harpoon 2" }, + { "", 'lua require("harpoon.ui").nav_file(3)', desc = "Navigate to harpoon 3" }, + { "", 'lua require("harpoon.ui").nav_file(4)', desc = "Navigate to harpoon 4" }, + + -- is not a valid sequence so use HJKL instead. + { "", 'lua require("harpoon.ui").nav_file(1)', desc = "Navigate to harpoon 1" }, + { "", 'lua require("harpoon.ui").nav_file(2)', desc = "Navigate to harpoon 2" }, + { "", 'lua require("harpoon.ui").nav_file(3)', desc = "Navigate to harpoon 3" }, + { "", 'lua require("harpoon.ui").nav_file(4)', desc = "Navigate to harpoon 4" }, + }, + opts = { + mark_branch = true, + menu = { + width = 100, + }, + }, + }, + + "tpope/vim-unimpaired", + "tpope/vim-surround", + "tpope/vim-sleuth", + + { + "nishigori/increment-activator", + keys = { + { "", desc = "Increment" }, + { "", desc = "Decrement" }, + }, + }, +} diff --git a/modules/home/nvim/lua/plugins/telescope.lua b/modules/home/nvim/lua/plugins/telescope.lua index 5da836a..18fbc48 100644 --- a/modules/home/nvim/lua/plugins/telescope.lua +++ b/modules/home/nvim/lua/plugins/telescope.lua @@ -15,7 +15,7 @@ return { version = false, -- telescope did only one release, so use HEAD for now keys = { { "f", "Telescope find_files", desc = "Find Files" }, - { "F", "Telescope live_grep", desc = "Grep" }, + { "F", "Telescope live_grep theme=ivy", desc = "Grep" }, { "gl", "Telescope git_commits", desc = "Git log" }, { "gs", "Telescope git_status", desc = "Git status" }, }, diff --git a/modules/home/nvim/lua/plugins/treesiter.lua b/modules/home/nvim/lua/plugins/treesiter.lua new file mode 100644 index 0000000..30e3a0d --- /dev/null +++ b/modules/home/nvim/lua/plugins/treesiter.lua @@ -0,0 +1,37 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + version = false, + build = ":TSUpdate", + event = { "BufReadPost", "BufNewFile" }, + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects" + }, + ---@type TSConfig + opts = { + highlight = { enable = true }, + indent = { enable = true }, + context_commentstring = { enable = true, enable_autocmd = false }, + ensure_installed = "all", + textobjects = { + select = { + enable = true, + lookahead = false, + + keymaps = { + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + ["ia"] = "@parameter.inner", + ["aa"] = "@parameter.outer", + }, + }, + }, + }, + ---@param opts TSConfig + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) + end, + }, +} diff --git a/modules/home/nvim/lua/plugins/ui.lua b/modules/home/nvim/lua/plugins/ui.lua index 4eb78c6..81e3895 100644 --- a/modules/home/nvim/lua/plugins/ui.lua +++ b/modules/home/nvim/lua/plugins/ui.lua @@ -70,6 +70,9 @@ return { yS = "Add Surroundings", } }, + dependencies = { + "afreakk/unimpaired-which-key.nvim", + }, config = function(_, opts) vim.opt["timeoutlen"] = 500 @@ -96,7 +99,7 @@ return { p = { "Past from system clipboard" }, P = { "Past line from system clipboard" }, }, { - prefix = "" + prefix = "", }) wk.register({ @@ -110,6 +113,50 @@ return { ["["] = { name = "+prev" }, ["g"] = { name = "+git" }, }) + + local uwk = require("unimpaired-which-key") + wk.register(uwk.normal_mode) + wk.register(uwk.normal_and_visual_mode, { mode = { "n", "v" } }) end, - }, - } + }, + + { + "NvChad/nvim-colorizer.lua", + event = "VeryLazy", + opts = { + filetypes = { + '*', + html = { names = true }, + css = { names = true }, + }, + user_default_options = { + mode = "virtualtext", + RGB = true, + RRGGBB = true, + names = false, + RRGGBBAA = true, + AARRGGBB = true, + rgb_fn = true, + hsl_fn = true, + tailwind = true, + }, + } + }, + + { + "stevearc/dressing.nvim", + lazy = true, + init = function() + ---@diagnostic disable-next-line: duplicate-set-field + vim.ui.select = function(...) + require("lazy").load({ plugins = { "dressing.nvim" } }) + return vim.ui.select(...) + end + ---@diagnostic disable-next-line: duplicate-set-field + vim.ui.input = function(...) + require("lazy").load({ plugins = { "dressing.nvim" } }) + return vim.ui.input(...) + end + end, + }, +}