Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rclawlor/regex-railroad.nvim
regex-railroad.nvim
https://github.com/rclawlor/regex-railroad.nvim
Last synced: about 2 months ago
JSON representation
regex-railroad.nvim
- Host: GitHub
- URL: https://github.com/rclawlor/regex-railroad.nvim
- Owner: rclawlor
- License: mit
- Created: 2024-03-30T10:23:48.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-22T18:50:13.000Z (8 months ago)
- Last Synced: 2024-05-22T19:56:50.472Z (8 months ago)
- Language: Rust
- Size: 59.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-neovim-pluginlist - rclawlor/regex-railroad.nvim - railroad.nvim) ![](https://img.shields.io/github/last-commit/rclawlor/regex-railroad.nvim) ![](https://img.shields.io/github/commit-activity/y/rclawlor/regex-railroad.nvim) (Coding / Regex)
README
# regex-railroad.nvim
![rust workflow](https://github.com/rclawlor/regex-railroad.nvim/actions/workflows/rust.yml/badge.svg)
![lua workflow](https://github.com/rclawlor/regex-railroad.nvim/actions/workflows/lua.yml/badge.svg)`regex-railroad.nvim` generates useful text and diagrams to help explain regular expressions in your code.
## Getting started
### Required dependencies
- [nvim-treesitter/nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) to extract the regular expression text### Installation
#### lazy.nvim
```lua
-- plugins/regex-railroad.lua:
return {
"rclawlor/regex-railroad.nvim",
tag = "0.0.3",
dependencies = { "nvim-treesitter/nvim-treesitter" }
}
```## Usage
Use `:RegexText` to generate a text description of the regular expression under your cursor, or `:RegexRailroad` to instead generate a railroad diagram!![regex-railroad](https://github.com/rclawlor/regex-railroad.nvim/assets/73249568/252a4bb9-4fd8-44e5-ab26-ba694e6049b1)
To remap the functions to something more convenient, use the following:
```lua
vim.api.nvim_set_keymap("n", "", "RegexText", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "", "RegexRailroad", {noremap = true, silent = true})
```
## Customisation
This section explains the available options for configuring `regex-railroad.nvim`### Setup function
```lua
require("regex-railroad").setup({
--- Github release of plugin
tag = "v0.0.3",
--- Highlight group used in :RegexText
highlight = {
bold = true,
fg = "fg",
bg = "bg"
}})
```## Supported Features
### Character classes| Feature | Example | Supported |
|:---------------------:|:---------:|:---------:|
| Character set | [ABC] | ✓ |
| Negated set | [^ABC] | ✓ |
| Range | [A-Z] | ✓ |
| Dot | . | ✓ |
| Word | \w | ✓ |
| Non-word | \W | ✓ |
| Digit | \d | ✓ |
| Non-digit | \D | ✓ |
| Whitespace | \s | ✓ |
| Non-whitespace | \S | ✓ |
| Unicode category | \p{L} | ✗ |
| Non-unicode category | \p{L} | ✗ |
| Unicode script | \p{Han} | ✗ |
| Non-unicode script | \P{Han} | ✗ |### Anchors
| Feature | Example | Supported |
|:---------------------:|:---------:|:---------:|
| Beginning | ^ | ✓ |
| End | $ | ✓ |
| Word boundary | \b | ✗ |
| Non-word boundary | \B | ✗ |### Groups & References
| Feature | Example | Supported |
|:---------------------:|:-------------:|:---------:|
| Capturing group | (ABC) | ✓ |
| Named capturing group | (?ABC) | ✓ |
| Numeric reference | \1 | ✗ |
| Non-capturing group | (?:ABC) | ✓ |### Lookaround
| Feature | Example | Supported |
|:---------------------:|:-------------:|:---------:|
| Positive lookahead | (?=ABC) | ✗ |
| Negative lookahead | (?!ABC) | ✗ |
| Positive lookbehind | (?<=ABC) | ✗ |
| Negative lookbehind | (?### Qualifiers & Alternation
| Feature | Example | Supported |
|:---------------------:|:-------------:|:---------:|
| Plus | + | ✓ |
| Star | * | ✗ |
| Quantifier | {1,3} | ✓ |
| Optional | ? | ✓ |
| Lazy | ? | ✗ |
| Alternation | \| | ✓ |