From 289888aa508ba8263888c6cd3271e41406efaa12 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Sat, 12 Aug 2023 15:37:48 +0800 Subject: [PATCH] feat: neovim - more plugins --- .../desktop/neovim/astronvim_user/init.lua | 67 +++++++++++++++---- .../neovim/astronvim_user/mappings.lua | 37 ++++++++-- home/base/desktop/neovim/default.nix | 17 ++++- 3 files changed, 97 insertions(+), 24 deletions(-) diff --git a/home/base/desktop/neovim/astronvim_user/init.lua b/home/base/desktop/neovim/astronvim_user/init.lua index 54f21b85..d5bace9b 100644 --- a/home/base/desktop/neovim/astronvim_user/init.lua +++ b/home/base/desktop/neovim/astronvim_user/init.lua @@ -66,24 +66,40 @@ return { end, }, - ---- Nushell + -- Enhanced matchparen.vim plugin for Neovim to highlight the outer pair. { - "LhKipp/nvim-nu", + "utilyre/sentiment.nvim", + version = "*", + event = "VeryLazy", -- keep for lazy loading + opts = { + -- config + }, + init = function() + -- `matchparen.vim` needs to be disabled manually in case of lazy loading + vim.g.loaded_matchparen = 1 + end, + }, + + -- joining blocks of code into oneline, or splitting one line into multiple lines. + { + 'Wansmer/treesj', + keys = { 'm', 'j', 's' }, + dependencies = { 'nvim-treesitter/nvim-treesitter' }, config = function() - require'nu'.setup({ - use_lsp_features = true, -- requires https://github.com/jose-elias-alvarez/null-ls.nvim - -- lsp_feature: all_cmd_names is the source for the cmd name completion. - -- It can be - -- * a string, which is interpreted as a shell command and the returned list is the source for completions (requires plenary.nvim) - -- * a list, which is the direct source for completions (e.G. all_cmd_names = {"echo", "to csv", ...}) - -- * a function, returning a list of strings and the return value is used as the source for completions - all_cmd_names = [[nu -c 'help commands | get name | str join "\n"']] + require('treesj').setup({--[[ your config ]]}) + end, + }, + + -- clipboard history manager + { + "gbprod/yanky.nvim", + config = function() + require("yanky").setup({ + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below }) end, - dependencies = { - {"nvim-treesitter/nvim-treesitter"}, - { "jose-elias-alvarez/null-ls.nvim"}, - } }, -- File explorer(Custom configs) @@ -135,6 +151,17 @@ return { end, }, + -- implementation/definition preview + { + 'rmagatti/goto-preview', + config = function() + require('goto-preview').setup {} + end + }, + + -- Undo tree + { "debugloop/telescope-undo.nvim", }, + -- Install lsp, formmatter and others via home manager instead of Mason.nvim -- LSP installations { @@ -215,6 +242,18 @@ return { opts.automatic_installation = false end, }, + + -- Fast and feature-rich surround actions + { + "kylechui/nvim-surround", + version = "*", -- Use for stability; omit to use `main` branch for the latest features + event = "VeryLazy", + config = function() + require("nvim-surround").setup({ + -- Configuration here, or leave empty to use defaults + }) + end + }, }, -- Configure require("lazy").setup() options diff --git a/home/base/desktop/neovim/astronvim_user/mappings.lua b/home/base/desktop/neovim/astronvim_user/mappings.lua index 1af3ccf9..6a736461 100644 --- a/home/base/desktop/neovim/astronvim_user/mappings.lua +++ b/home/base/desktop/neovim/astronvim_user/mappings.lua @@ -4,7 +4,11 @@ -- lower level configuration and more robust one. (which-key will -- automatically pick-up stored data by this setting.) local utils = require "astronvim.utils" + require("telescope").load_extension("refactoring") +require("telescope").load_extension("yank_history") +require("telescope").load_extension("undo") + return { -- first key is the mode n = { @@ -21,13 +25,28 @@ return { ['sp'] ={'lua require("spectre").open_file_search({select_word=true})', desc = "Search on current file" }, -- refactoring - ["ri"] = { function() require('refactoring').refactor('Inline Variable') end, desc = "Refactoring Inline Variable" }, + ["ri"] = { function() require('refactoring').refactor('Inline Variable') end, desc = "Inverse of extract variable" }, ["rb"] = { function() require('refactoring').refactor('Extract Block') end, desc = "Extract Block" }, ["rbf"] = { function() require('refactoring').refactor('Extract Block To File') end, desc = "Extract Block To File" }, ["rr"] = { function() require('telescope').extensions.refactoring.refactors() end, desc = "Prompt for a refactor to apply" }, - ["rp"] = { function() require('refactoring').debug.printf({below = false}) end, desc = "Print debug info" }, - ["rv"] = { function() require('refactoring').debug.print_var() end, desc = "Print debug var" }, - ["rc"] = { function() require('refactoring').debug.cleanup({}) end, desc = "Cleanup debugging" }, + ["rp"] = { function() require('refactoring').debug.printf({below = false}) end, desc = "Insert print statement to mark the calling of a function" }, + ["rv"] = { function() require('refactoring').debug.print_var() end, desc = "Insert print statement to print a variable" }, + ["rc"] = { function() require('refactoring').debug.cleanup({}) end, desc = "Cleanup of all generated print statements" }, + + -- yank_history + ["yh"] = { function() require("telescope").extensions.yank_history.yank_history() end, desc = "Preview Yank History" }, + ["p"] = {"(YankyPutAfter)", desc="YankyPutAfter" }, + ["P"] = {"(YankyPutBefore)", desc="YankyPutBefore" }, + + -- undo history + ["uh"] = {"Telescope undo", desc="Telescope undo" }, + + -- implementation/definition preview + ["gpd"] = { "lua require('goto-preview').goto_preview_definition()", desc="goto_preview_definition" }, + ["gpt"] = { "lua require('goto-preview').goto_preview_type_definition()", desc="goto_preview_type_definition" }, + ["gpi"] = { "lua require('goto-preview').goto_preview_implementation()", desc="goto_preview_implementation" }, + ["gP" ] = { "lua require('goto-preview').close_all_win()", desc="close_all_win" }, + ["gpr"] = { "lua require('goto-preview').goto_preview_references()", desc="goto_preview_references" }, }, v = { -- search and replace globally @@ -35,11 +54,15 @@ return { }, x = { -- refactoring - ["ri"] = { function() require('refactoring').refactor('Inline Variable') end, desc = "Refactoring Inline Variable" }, - ["re"] = { function() require('refactoring').refactor('Extract Function') end, desc = "Extract Function" }, + ["ri"] = { function() require('refactoring').refactor('Inline Variable') end, desc = "Inverse of extract variable" }, + ["re"] = { function() require('refactoring').refactor('Extract Function') end, desc = "Extracts the selected code to a separate function" }, ["rf"] = { function() require('refactoring').refactor('Extract Function To File') end, desc = "Extract Function To File" }, - ["rv"] = { function() require('refactoring').refactor('Extract Variable') end, desc = "Extract Variable" }, + ["rv"] = { function() require('refactoring').refactor('Extract Variable') end, desc = "Extracts occurrences of a selected expression to its own variable" }, ["rr"] = { function() require('telescope').extensions.refactoring.refactors() end, desc = "Prompt for a refactor to apply" }, + + -- yank_history + ["p"] = {"(YankyPutAfter)", desc="YankyPutAfter" }, + ["P"] = {"(YankyPutBefore)", desc="YankyPutBefore" }, }, t = { -- setting a mapping to false will disable it diff --git a/home/base/desktop/neovim/default.nix b/home/base/desktop/neovim/default.nix index 4acdef5d..573426fb 100644 --- a/home/base/desktop/neovim/default.nix +++ b/home/base/desktop/neovim/default.nix @@ -35,10 +35,11 @@ # Horizontal Split Terminal: ` + th` # Vertical Split Terminal: ` + tv` # Open IPython REPL: ` + tp` -# Opening LSP symbols: ` + lS` # Toggle line wrap: ` + uw` # Show line diagnostics: `gl` +# Show function/variable info: `K` # Go to definition: `gd` +# References of a symbol: `gr` # # Switching between windows: ` + h/j/k/l` # Resizing windows: ` + Up/Down/Left/Right` @@ -52,10 +53,11 @@ # # Toggle buffer auto formatting: ` + uf` # Format Document: ` + lf` -# Comment Line: ` + /` -# Can be used in visual mode # Code Actions: ` + la` # Rename: ` + lr` +# Opening LSP symbols: ` + lS` +# Comment Line: ` + /` +# Can be used in visual mode # Open filepath/URL at cursor: `gx` # This is a neovim builtin command # Find files by name(fzf): ` + ff` @@ -89,17 +91,26 @@ # 1. Open Spectre search and replace panel: ` + ss` # 2. search and replace in command line: `find -name "*.nix" | sad '' '' | delta` # +# Add surrounding characters: `ysiw'` (will add `'` around the word under cursor) +# Delete surrounding characters: `ds'` (will delete `'` around the word under cursor) +# Change surrounding characters: `cs'"` (will change `'` to `"` around the word under cursor) +# # Joining a Selection of Lines With Space: `:join` # Joining without spaces: `:join!` +# Join with lsp intellegence(treesj): ` + j` +# Splitting a Line into Multiple Lines(treesj): ` + s` # # Toggle text's case: `~` # Convert to uppercase: `U` # Convert to lowercase: `u` # # Save the selected text to a file: `:w filename` (will show `:'<,'>w filename`) +# Show all Yank History: `: + yh` +# Show undo history: `: + uh` # # ...... # See https://astronvim.com/Basic%20Usage/walkthrough +# And ./astronvim_user/mapping.lua # #e############################################################################# {