Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cshuaimin/ssr.nvim
Treesitter based structural search and replace plugin for Neovim.
https://github.com/cshuaimin/ssr.nvim
lua neovim-plugin nvim nvim-treesitter tree-sitter
Last synced: about 1 month ago
JSON representation
Treesitter based structural search and replace plugin for Neovim.
- Host: GitHub
- URL: https://github.com/cshuaimin/ssr.nvim
- Owner: cshuaimin
- License: mit
- Created: 2022-07-31T10:27:47.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T02:43:33.000Z (2 months ago)
- Last Synced: 2024-03-20T03:44:33.369Z (2 months ago)
- Topics: lua, neovim-plugin, nvim, nvim-treesitter, tree-sitter
- Language: Lua
- Homepage:
- Size: 54.7 KB
- Stars: 834
- Watchers: 10
- Forks: 11
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-neovim - cshuaimin/ssr.nvim - Treesitter-based structural search and replace. (Editing Support / Scrollbar)
- awesome-stars - cshuaimin/ssr.nvim - Treesitter based structural search and replace plugin for Neovim. (Lua)
- awesome-stars - cshuaimin/ssr.nvim - Treesitter based structural search and replace plugin for Neovim. (Lua)
- awesome-stars - cshuaimin/ssr.nvim - Treesitter based structural search and replace plugin for Neovim. (Lua)
- awesome-neovim - cshuaimin/ssr.nvim - Treesitter-based structural search and replace. (Editing Support / Scrollbar)
- awesome-neovim - cshuaimin/ssr.nvim - Treesitter-based structural search and replace. (Editing Support / Scrollbar)
- awesome-stars - ssr.nvim
README
# ssr.nvim
[Structural search and replace](https://www.jetbrains.com/help/idea/structural-search-and-replace.html) for Neovim.
https://user-images.githubusercontent.com/24775746/199903092-a499dee1-af0a-444f-8ac1-24102454196f.mov
## Installation
with packer.nvim:
```lua
use {
"cshuaimin/ssr.nvim",
module = "ssr",
-- Calling setup is optional.
config = function()
require("ssr").setup {
border = "rounded",
min_width = 50,
min_height = 5,
max_width = 120,
max_height = 25,
adjust_window = true,
keymaps = {
close = "q",
next_match = "n",
prev_match = "N",
replace_confirm = "",
replace_all = "",
},
}
end
}
```then add a mapping to open SSR:
```lua
vim.keymap.set({ "n", "x" }, "sr", function() require("ssr").open() end)
```## Usage
First put your cursor on the structure you want to search and replace (if you
are not sure, select a region instead), then open SSR by pressing `sr`.In the SSR float window you can see the placeholder search code, you can
replace part of it with wildcards. A wildcard is an identifier starts with `$`,
like `$name`. A `$name` wildcard in the search pattern will match any AST node
and `$name` will reference it in the replacement.Press `` to replace all matches in current buffer, or `` to
choose which match to replace.## The context
When opening SSR, the cursor position is important, you need to put the cursor
on the structure you want to search. If the placeholder code is not correct,
exit SSR with `q` and select the region instead.ssr.nvim parses your search pattern to syntax trees to perform structural
searching. However directly parsing code without context is not accurate, for
example TypeScript function argument `foo: number` will be parsed as a label
without context, so ssr.nvim parses pattern in it's original context.## Limitations
ssr.nvim performs searching and replacing at AST level and doesn't understand
code as much as LSP servers do. Use LSP server's ssr implementation if possible.