feat: neovim - add flash.nvim

This commit is contained in:
Ryan Yin
2023-08-13 00:18:07 +08:00
parent 9c5a1b12ef
commit d3553ae104
3 changed files with 57 additions and 13 deletions

View File

@@ -44,25 +44,49 @@ Remove all unused plugins:
Provided by nvim-treesitter.
| Action | Shortcut |
| ----------------- | -------- |
| init selection | `<Ctrl-space>` |
| node incremental | `<Ctrl-space>` |
| scope incremental | `<Alt-Space>` |
| Action | Shortcut |
| ----------------- | -------------- |
| init selection | `<Ctrl-space>` |
| node incremental | `<Ctrl-space>` |
| scope incremental | `<Alt-Space>` |
| 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<text>`
- Execute `A<text>` 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<text>`
- 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 |

View File

@@ -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" },
-- <ctrl + s>, Command-line mode(prefix: `:`)
{ "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" },
},
},
{
'nvim-telescope/telescope.nvim', branch = '0.1.x',
dependencies = { 'nvim-lua/plenary.nvim' },

View File

@@ -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" ] = { "<cmd>lua require('goto-preview').close_all_win()<CR>", desc="close_all_win" },
["gpr"] = { "<cmd>lua require('goto-preview').goto_preview_references()<CR>", desc="goto_preview_references" },
},
-- Visual mode
v = {
-- search and replace globally
['<leader>sw'] = {'<esc><cmd>lua require("spectre").open_visual()<CR>', desc = "Search current word" },
},
-- visual mode(what's the difference between v and x???)
x = {
-- refactoring
["<leader>ri"] = { function() require('refactoring').refactor('Inline Variable') end, desc = "Inverse of extract variable" },
@@ -64,8 +66,4 @@ return {
["p"] = {"<Plug>(YankyPutAfter)", desc="YankyPutAfter" },
["P"] = {"<Plug>(YankyPutBefore)", desc="YankyPutBefore" },
},
t = {
-- setting a mapping to false will disable it
-- ["<esc>"] = false,
},
}