An open API service indexing awesome lists of open source software.

https://github.com/beixiyo/vv-replace.nvim

VSCode-style search & replace powered by ripgrep. VSCode 风搜索替换(基于 ripgrep)
https://github.com/beixiyo/vv-replace.nvim

lua neovim neovim-plugin nvim nvim-plugin replace ripgrep search

Last synced: 16 days ago
JSON representation

VSCode-style search & replace powered by ripgrep. VSCode 风搜索替换(基于 ripgrep)

Awesome Lists containing this project

README

          

vv-replace.nvim


VSCode 风的搜索替换面板 — 默认纯文本、smart-case、diff 预览


Requires Neovim 0.10+
Lua
Requires ripgrep ≥13

---

## 依赖

| 依赖 | 说明 |
|------|------|
| [Neovim ≥ 0.10](https://github.com/neovim/neovim) | `vim.system`、extmark `invalid`、`vim.fs.normalize` |
| [ripgrep ≥ 13](https://github.com/BurntSushi/ripgrep) | 搜索引擎,使用 `--json` 流式输出 + `--replace` 计算替换结果 |
| [vv-utils.nvim](https://github.com/beixiyo/vv-utils.nvim) | 共享工具库(fs、help_panel、ui_window) |

## 为什么要这个插件

[grug-far.nvim](https://github.com/MagicDuck/grug-far.nvim) 日常使用有几处不顺手:

| | grug-far | vv-replace |
|---|---|---|
| **默认模式** | 正则 — 输入 `foo(` 或 `a.b` 需手动转义 | 纯文本(plainText),`` 切正则 |
| **大小写** | 手敲 `-s`/`-i` 到 Flags 框 | smart-case:全小写自动 `-i`,含大写自动 `-s` |
| **输入框** | 5 个(Search/Replace/Flags/Files/Paths) | 文件模式 2 个,项目模式 5 个 |
| **替换预览** | 实时 diff | 单行 inline diff(匹配标红 + 替换绿色);光标移动时自动在源窗口预览整个文件的 diff |

## 安装

```lua
{
'beixiyo/vv-replace.nvim',
dependencies = { 'beixiyo/vv-utils.nvim' },
cmd = { 'VVReplace', 'VVReplaceFile', 'VVReplaceClose', 'VVReplaceToggle' },
keys = { 'sR', 'sr' },
---@type VVReplaceConfig
opts = {
position = 'right', -- 'left' | 'right'
width = 60, -- 面板宽度
debounce_ms = 200, -- 输入去抖延迟
max_results = 10000, -- 单次搜索匹配上限
context_lines = 0, -- rg --context=N(0 关闭)
default_mode = 'plainText', -- 'plainText' | 'regex'
rg_extra_args = {}, -- 追加给 rg 的额外参数
keymaps = {
next_input = '', -- 下一个输入框
toggle_mode = '', -- 切换模式 plainText ↔ regex
replace_all = 'r', -- 替换全部(带确认)
goto_match = '', -- 跳转到源文件对应行
close = 'q',
help = 'g?',
},
icons = {
plain = '󰊄', -- mode 徽章: plainText
regex = '', -- mode 徽章: regex
next_input = '󰁔',
toggle_mode = '󰁨',
goto_match = '',
replace_all = '',
close = '',
help = '󰌌',
title = '',
},
},
}
```

## 配置

| 选项 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| `position` | `'left' \| 'right'` | `'right'` | 面板位置 |
| `width` | `integer` | `60` | 面板宽度 |
| `debounce_ms` | `integer` | `200` | 输入去抖延迟(ms) |
| `max_results` | `integer` | `10000` | 单次搜索匹配上限,防大项目卡死 |
| `context_lines` | `integer` | `0` | `rg --context=N`,0 = 关闭 |
| `default_mode` | `'plainText' \| 'regex'` | `'plainText'` | 默认搜索模式 |
| `rg_extra_args` | `string[]` | `{}` | 追加给所有 rg 调用的额外参数(如 `{ '--hidden' }`) |
| `keymaps` | `VVReplaceKeymaps` | *见上方* | 面板内键位,可逐项覆盖 |
| `icons` | `VVReplaceIcons` | *见上方* | NerdFont 图标;非 NerdFont 用户可改 ASCII |

### 入口键位

| 键 | 作用 |
|----|------|
| `sR` | 项目级搜索替换(5 字段:Search / Replace / Include / Exclude / Cwd) |
| `sr` | 当前文件搜索替换(2 字段:Search / Replace) |
| `sR`(visual) | 用选区预填 Search |