Vim基础篇(三十一)——字符替换插件vim-clap
Vim基础篇(三十一)——字符替换插件vim-clap
前言:
在linux下编程,终端最是常用的工具,将Vim和Terminal配合好使用将大大提高效率。
1 介绍
vim-clap 是一个强大的Vim插件,提供了多种功能,其中之一是字符替换功能。它允许用户在Vim中快速查找和替换文本,支持正则表达式和多文件操作,非常适合处理大量文本数据。
- 异步处理(Async)
- 所有搜索操作在后台异步执行,不会阻塞编辑器。
- 提供流畅的用户体验,即使在大型项目中也能快速响应。
- 无需外部依赖(可选)
- 默认使用 Vim 内置功能实现,无需安装
fzf、ripgrep等外部工具。 - 可选集成
rg(ripgrep)、git等工具以提升性能。
- 默认使用 Vim 内置功能实现,无需安装
- 丰富的源(Providers)
支持多种查找模式,例如:Clap files:文件查找(支持.gitignore)Clap git_files:Git 管理的文件Clap grep:文本内容搜索(类似:Ag)Clap buffers:打开的缓冲区切换Clap marks:书签跳转Clap commands:Vim 命令补全Clap keymaps:查看快捷键映射Clap help:帮助文档搜索Clap symbols:LSP 符号查找(需配合 LSP)Clap quickfix/loclist:快速修复列表浏览
- 高度可定制
- 支持自定义主题、布局、高亮、按键映射等。
- 可通过 Lua(Neovim)或 Vim script 配置。
- 良好的 UI 体验
- 使用浮动窗口(floating window)或分屏显示结果(Neovim 推荐用浮窗)。
- 实时模糊匹配 + 高亮匹配字符。
- 与插件生态兼容
- 可与
coc.nvim、nvim-lspconfig、telescope.nvim风格互补(但更轻量)。
- 可与
2 安装
vim-plug插件为例,在vim中添加以下配置进行安装。在克隆完仓库后会自动执行命令 :Clap install-binary! 来安装可选的二进制文件以提升性能。
1 | Plug 'liuchengxu/vim-clap', { 'do': ':Clap install-binary!' } |
如果没有自动出发执行指令,也可在vim中执行手动触发,:Clap install-binary! 会下载预编译的二进制助手,用于加速某些功能(如 grep )。

安装成功后可看到已经编译好的二进制文件maple。

3 配置
在vim添加以下配置
1 | let g:clap_project_root_markers = ['.git', 'go.mod', 'package.json'] " 根目录标识。 |
4 使用
以下是vim-clap支持的指令。
| 命令 | 描述 | 依赖 |
|---|---|---|
:Clap blines |
Lines in the current buffer | none |
:Clap buffers |
Open buffers | none |
:Clap colors |
Colorschemes | none |
:Clap command |
Command | none |
:Clap hist: 或 :Clap command_history |
Command history | none |
:Clap hist/ 或 :Clap search_history |
Search history | none |
:Clap filetypes |
File types | none |
:Clap help_tags |
Help tags | none |
:Clap jumps |
Jumps | none |
:Clap lines |
Lines in the loaded buffers | none |
:Clap marks |
Marks | none |
:Clap maps |
Maps | none |
:Clap quickfix |
Entries of the quickfix list | none |
:Clap loclist |
Entries of the location list | none |
:Clap registers |
Registers | none |
:Clap yanks |
Yank stack of the current vim session | none |
:Clap history |
Open buffers and v:oldfiles | none |
:Clap windows |
Windows | none |
:Clap providers |
List the vim-clap providers | none |
:Clap bcommits |
Git commits for the current buffer | git |
:Clap commits |
Git commits | git |
:Clap gfiles 或 :Clap git_files |
Files managed by git | git |
:Clap git_diff_files |
Files managed by git and having uncommitted changes | git |
:Clap live_grep (deprecated) |
Grep using word-regexp matcher | rg |
:Clap dumb_jump |
Definitions/References using regexp with grep fallback | rg with –pcre2 |
:Clap files |
Files | none |
:Clap filer |
Ivy-like file explorer | none |
:Clap grep+ |
Grep using fuzzy matcher | none |
:Clap igrep |
A combo of filer and grep | none |
:Clap tags |
Tags in the current buffer | none |
:Clap tagfiles |
Search existing tagfiles | none |
:Clap proj_tags |
Tags in the current project | universal-ctags (+json) |
:Clap recent_files |
Persistent ordered history of recent files | none |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 OnlyCalm's Blog!
评论
ValineGitalk







