ray-x/sad.nvim

github github
search
star 45
stars
alert-circle 0
open issues
users 1
subscribers
git-branch 0
forks
CREATED

2021-12-03

UPDATED

27 days ago


sad.nvim

Space Age seD in neovim. A project wide find and replace plugin with sad & fzf

This plug is a wrapper for sad by ms-jqd

You need

  • install sad
  • fzf so you can confirm/select the matches to apply your changes
  • by default the plugin using 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 'ray-x/guihua.lua'  "lua GUI lib
Plug 'ray-x/sad.nvim'

Configure

require'sad'.setup({
  diff = 'delta', -- you can use `diff`, `diff-so-fancy`
  ls_file = 'fd', -- also git ls_file
  exact = false, -- exact match
  vsplit = true, -- 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
:Sad oldtext newtext
  • add file filter, e.g lua files
:Sad oldtext newtext lua
  • The lua way, you can add key map

-- 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('<word>') or visual select with 'new' for md files
lua require'sad'.replace(nil, 'new', 'md')

-- or replace expand('<word>') or visual select with your input for md files
lua require'sad'.replace(nil, nil, 'md')

confirm or cancel

  • <Tab> To toggle the individual item in the replacement list
  • <CR> to confirm and apply all the replacement
  • <Esc> to cancel all changes
  • <Ctrl-a> toggle select all

Alternatives

  • vim&neovim: far.vim a vim plugin with python & vimscript

  • neovim: nvim-spectre Lua plugin, find with rg and replace with sed

    and most importantly, with realtime preview