From d3553ae104f221ee7fe5c75214f57da7d34b142b Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Sun, 13 Aug 2023 00:18:07 +0800 Subject: [PATCH] feat: neovim - add flash.nvim --- home/base/desktop/neovim/README.md | 40 +++++++++++++++---- .../desktop/neovim/astronvim_user/init.lua | 22 ++++++++++ .../neovim/astronvim_user/mappings.lua | 8 ++-- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/home/base/desktop/neovim/README.md b/home/base/desktop/neovim/README.md index bd782982..cdd74b93 100644 --- a/home/base/desktop/neovim/README.md +++ b/home/base/desktop/neovim/README.md @@ -44,25 +44,49 @@ Remove all unused plugins: Provided by nvim-treesitter. -| Action | Shortcut | -| ----------------- | -------- | -| init selection | `` | -| node incremental | `` | -| scope incremental | `` | +| Action | Shortcut | +| ----------------- | -------------- | +| init selection | `` | +| node incremental | `` | +| scope incremental | `` | | node decremental | `Backspace` | +## Search and Jump + +Provided by [flash.nvim](https://github.com/folke/flash.nvim), it's a intelligent search and jump plugin. + +1. It enhaces the default search and jump behavior of neovim.(search with prefix `/`) + +| Action | Shortcut | +| ----------------- | -------------------------------------------------------------------------------- | +| Search | `/`(normal search), `s`(disable all code highlight, only highlight matches) | +| Treesitter Search | `yR`(arround your matches, all the surrounding Treesitter nodes will be labeled) | + ## Text Manipulation - Add at the end of multiple lines: `:normal A` - - Execute `A` on each line + - visual mode(v) - `A` appends text at the end of each line - - Select lines using visual mode first - Add at the end of visual block: `:A` - - Append text at the end of each line in the selected block(visual block mode) + - visual block mode(ctrl + v) + - Append text at the end of each line in the selected block - If position exceeds line end, neovim adds spaces automatically +- Delete the last char of multiple lines: `:normal $x` + - Execute `$x` on each line + - visual mode(v) + - `$` moves cursor to the end of line + - `x` deletes the character under the cursor + +- Delete the last word of multiple lines: `:normal $bD` + - Execute `$bD` on each line + - visual mode(v) + - `$` moves cursor to the end of line + - `b` moves cursor to the beginning of the last word + - `D` deletes from cursor to the end of line + ## Commands & Shortcuts | Action | Shortcut | diff --git a/home/base/desktop/neovim/astronvim_user/init.lua b/home/base/desktop/neovim/astronvim_user/init.lua index e8090150..6ba39944 100644 --- a/home/base/desktop/neovim/astronvim_user/init.lua +++ b/home/base/desktop/neovim/astronvim_user/init.lua @@ -272,6 +272,28 @@ return { end }, + -- Flash enhances the built-in search/jump functionality. + { + "folke/flash.nvim", + event = "VeryLazy", + vscode = true, + ---@type Flash.Config + opts = {}, + -- stylua: ignore + keys = { + -- Normal, Visual, or Operator-pending modes + { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, + -- confict with nvim-surround's keys + { "S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, + -- command: yr + { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, + -- command: yR + { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, + -- , Command-line mode(prefix: `:`) + { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, + }, + }, + { 'nvim-telescope/telescope.nvim', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim' }, diff --git a/home/base/desktop/neovim/astronvim_user/mappings.lua b/home/base/desktop/neovim/astronvim_user/mappings.lua index 6a736461..8f6b9816 100644 --- a/home/base/desktop/neovim/astronvim_user/mappings.lua +++ b/home/base/desktop/neovim/astronvim_user/mappings.lua @@ -10,7 +10,7 @@ require("telescope").load_extension("yank_history") require("telescope").load_extension("undo") return { - -- first key is the mode + -- normal mode n = { -- second key is the lefthand side of the map -- mappings seen under group name "Buffer" @@ -48,10 +48,12 @@ return { ["gP" ] = { "lua require('goto-preview').close_all_win()", desc="close_all_win" }, ["gpr"] = { "lua require('goto-preview').goto_preview_references()", desc="goto_preview_references" }, }, + -- Visual mode v = { -- search and replace globally ['sw'] = {'lua require("spectre").open_visual()', desc = "Search current word" }, }, + -- visual mode(what's the difference between v and x???) x = { -- refactoring ["ri"] = { function() require('refactoring').refactor('Inline Variable') end, desc = "Inverse of extract variable" }, @@ -64,8 +66,4 @@ return { ["p"] = {"(YankyPutAfter)", desc="YankyPutAfter" }, ["P"] = {"(YankyPutBefore)", desc="YankyPutBefore" }, }, - t = { - -- setting a mapping to false will disable it - -- [""] = false, - }, }