Serpl
serpl is a terminal user interface (TUI) application that allows users to search and replace keywords in an entire folder, similar to the functionality available in VS Code.
https://github.com/yassinebridi/serpl/assets/18403595/c63627da-7984-4e5f-b1e2-ff14a5d44453
Table of Contents
- Features
- Installation
- Usage
- Panes
- Neovim Integration using toggleterm
- License
- Contributing
- Acknowledgements
- Similar Projects
Features
- Search for keywords across an entire project folder.
- Replace keywords with options for preserving case.
- Interactive preview of search results.
- Keyboard navigation for efficient workflow.
- Configurable key bindings and search modes.
Installation and Update
Prerequisites
Steps
- Install the application using Cargo:
- Update the application using Cargo:
- Run the application:
Binaries
Check the releases page for the latest binaries.
OS Specific Installation
Arch Linux
serpl can be installed from the official repositories using pacman:
Nix/NixOS
serpl is included in nixpkgs since 24.11, and can be installed via Nix in different ways:
On standalone Nix setups:
On NixOS (via configuration.nix or similar):
{pkgs, ...}: {
environment.systemPackages = [pkgs.serpl];
}
On Home-Manager:
{pkgs, ...}: {
home.packages = [pkgs.serpl];
}
Usage
Basic Commands
- Start the application in the current directory:
- Start the application and provide the project root path:
Key Bindings
Default key bindings can be customized through the config.json file.
Default Key Bindings
| Key Combination | Action |
|---|---|
Ctrl + c |
Quit |
Ctrl + b |
Help |
Tab |
Switch between tabs |
Backtab |
Switch to previous tabs |
Ctrl + o |
Process replace |
Ctrl + n |
Toggle search and replace modes |
Enter |
Execute search (for large folders) |
g / Left / h |
Go to top of the list |
G / Right / l |
Go to bottom of the list |
j / Down |
Move to the next item |
k / Up |
Move to the previous item |
d |
Delete selected file or line |
Esc |
Exit the current pane or dialog |
Enter (in dialogs) / y |
Confirm action |
Esc (in dialogs) / n |
Cancel action |
h, l, Tab (in dialogs) |
Navigate dialog options |
Configuration
serpl uses a configuration file to manage key bindings and other settings. By default, the path to the configuration file can be found by running serpl --version. You can use various file formats for the configuration, such as JSON, JSON5, YAML, TOML, or INI.
Example Configurations
{
keybindings: {
"<Ctrl-d>": "Quit",
"<Ctrl-c>": "Quit",
"<Tab>": "LoopOverTabs",
"<Backtab>": "BackLoopOverTabs",
"<Ctrl-o>": "ProcessReplace",
},
}
keybindings:
"<Ctrl-d>": "Quit"
"<Ctrl-c>": "Quit"
"<Tab>": "LoopOverTabs"
"<Backtab>": "BackLoopOverTabs"
"<Ctrl-o>": "ProcessReplace"
[]
= "Quit"
= "Quit"
= "LoopOverTabs"
= "BackLoopOverTabs"
= "ProcessReplace"
[keybindings]
<Ctrl-d> = Quit
<Ctrl-c> = Quit
<Tab> = LoopOverTabs
<Backtab> = BackLoopOverTabs
<Ctrl-o> = ProcessReplace
You can customize the key bindings by modifying the configuration file in the format of your choice.
Panes
Search Input
- Input field for entering search keywords.
- Toggle search modes (Simple, Match Case, Whole Word, Regex).
[!TIP] If current directory is considerebly large, you have to click
Enterto start the search.
Replace Input
- Input field for entering replacement text.
- Toggle replace modes (Simple, Preserve Case).
Search Results Pane
- List of files with search results.
- Navigation to select and view files.
- Option to delete files from the search results.
Preview Pane
- Display of the selected file with highlighted search results.
- Navigation to view different matches within the file.
- Option to delete individual lines containing matches.
Neovim Integration using toggleterm
Check out the toggleterm.nvim plugin for Neovim, which provides a terminal that can be toggled with a key binding. Or you can use the following configuration, if you are using AstroNvim:
return
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
(WIP)
Acknowledgements
- This project was inspired by the VS Code search and replace functionality.
- This project is built using the awesome ratatui.rs library, and build on top of their Component Template.
Similar Projects
- repgrep: An interactive replacer for ripgrep that makes it easy to find and replace across files on the command line.