Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ray-x/sad.nvim
Space Age seD in Neovim. A project-wide find and replace plugin for Neovim.
https://github.com/ray-x/sad.nvim
find-and-replace neovim neovim-plugin
Last synced: 8 days ago
JSON representation
Space Age seD in Neovim. A project-wide find and replace plugin for Neovim.
- Host: GitHub
- URL: https://github.com/ray-x/sad.nvim
- Owner: ray-x
- License: gpl-3.0
- Created: 2021-12-03T07:27:32.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-27T23:06:07.000Z (12 days ago)
- Last Synced: 2024-10-28T03:15:24.558Z (12 days ago)
- Topics: find-and-replace, neovim, neovim-plugin
- Language: Lua
- Homepage:
- Size: 45.9 KB
- Stars: 193
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim - ray-x/sad.nvim - Space Age seD in Neovim. Batch file edit tool, a wrapper for [sad](https://github.com/ms-jpq/sad) (Search / PHP)
README
# sad.nvim
Space Age seD in neovim. A project wide find and replace plugin with sad & fzf
This plug is a wrapper for [sad](https://github.com/ms-jpq/sad) by `ms-jqd`
You need
- [install sad](https://github.com/ms-jpq/sad#get-sad-now)
- [fzf](https://github.com/junegunn/fzf) so you can confirm/select the matches to apply your changes
- by default the plugin using [fd](https://github.com/sharkdp/fd) to list all files in the current folder, you can use
`git ls_file`
- a pager tool, e.g. `delta`https://user-images.githubusercontent.com/1681295/144705615-658ab025-f2a3-4857-b9d3-e5e2142bf316.mp4
# install
## Plug
```
Plug 'ray-x/guihua.lua', {'do': 'cd lua/fzy && make' }
Plug 'ray-x/sad.nvim'
```## packer
```lua
require("packer").startup({
function(use)
use({ "wbthomason/packer.nvim" })
use({
"ray-x/sad.nvim",
requires = { "ray-x/guihua.lua", run = "cd lua/fzy && make" },
config = function()
require("sad").setup{}
end,
})
end,
})
```# Configure
```lua
require'sad'.setup({
debug = false, -- print debug info
diff = 'delta', -- you can use `less`, `diff-so-fancy`
ls_file = 'fd', -- also git ls-files
exact = false, -- exact match
vsplit = false, -- split sad window the screen vertically, when set to number
-- it is a threadhold when window is larger than the threshold sad will split vertically,
height_ratio = 0.6, -- height ratio of sad window when split horizontally
width_ratio = 0.6, -- height ratio of sad window when split vertically})
```# usage
- If you put your cursor on the word want to replace or visual select the word you want to replace, simply run
```
:Sad
```You will be prompt to input new word to be replace
- replace all `oldtext` to `newtext` for all project files
```vim
:Sad oldtext newtext
```- add file filter, e.g lua files
```vim
:Sad oldtext newtext lua
```- The lua way, you can add key map
```lua
-- replace old with new
lua require'sad'.replace('old', 'new')-- or replace old with input for 'md' files
lua require'sad'.replace('old', nil, 'md')-- or replace expand('') or visual select with 'new' for md files
lua require'sad'.replace(nil, 'new', 'md')-- or replace expand('') or visual select with your input for md files
lua require'sad'.replace(nil, nil, 'md')```
```vim
"capture group "123" -> 🌈123🌈
:Sad "(\d+)" '🌈$1🌈'"capture group 123 -> 🌈123🌈
:Sad (\d+) '🌈$1🌈'" multiple lines:"
Sad (firstKey:firstValue\n\s*secondKey):secondVal $1:newSecondValue
" or use ${1}
Sad (firstKey:firstValue\n\s*secondKey:)secondVal ${1}newSecondValue```
## confirm or cancel
- \ To toggle the individual item in the replacement list
- \ to confirm and apply all the replacement
- \ to cancel all changes
- \ toggle select all# Alternatives
- vim&neovim: [far.vim](https://github.com/brooth/far.vim) a vim plugin with python & vimscript
- neovim: [nvim-spectre](https://github.com/windwp/nvim-spectre) Lua plugin, find with `rg` and replace with `sed`
and most importantly, with realtime preview