• Stars
    star
    623
  • Rank 72,088 (Top 2 %)
  • Language
    Lua
  • Created almost 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Describe the regexp under the cursor

nvim-regexplainer

Lua GitHub Workflow Status Number of users on dotfyle

Describe the regular expression under the cursor.

Regexplainer.mov

Heavily inspired by the venerable atom-regexp-railroad.

👉 NOTE: Requires Neovim 0.7 👈

🚚 Installation

use { 'bennypowers/nvim-regexplainer',
      config = function() require'regexplainer'.setup() end,
      requires = {
        'nvim-treesitter/nvim-treesitter',
        'MunifTanjim/nui.nvim',
      } }

You need to install regex with nvim-treesitter, as well as the grammar for whichever host language you're using. So for example if you wish to use Regexplainer with TypeScript sources, you need to do this:

:TSInstall regex typescript

🤔 Config

-- defaults
require'regexplainer'.setup {
  -- 'narrative'
  mode = 'narrative', -- TODO: 'ascii', 'graphical'

  -- automatically show the explainer when the cursor enters a regexp
  auto = false,

  -- filetypes (i.e. extensions) in which to run the autocommand
  filetypes = {
    'html',
    'js',
    'cjs',
    'mjs',
    'ts',
    'jsx',
    'tsx',
    'cjsx',
    'mjsx',
  },

  -- Whether to log debug messages
  debug = false, 

  -- 'split', 'popup'
  display = 'popup',

  mappings = {
    toggle = 'gR',
    -- examples, not defaults:
    -- show = 'gS',
    -- hide = 'gH',
    -- show_split = 'gP',
    -- show_popup = 'gU',
  },

  narrative = {
    separator = '\n',
  },
}

display

Regexplainer offers a small variety of display modes to suit your preferences.

Split Window

Set to split to display the explainer in a window below the editor. The window will be reused, and has the filetype Regexplainer

Popup Below Cursor

Set to popup (the default) to display the explainer in a popup below the cursor. When the cursor moves, the popup closes. if auto is set, the popup will automatically display whenever the cursor moves inside a regular expression You can call show with your own display type to override your config

require'regexplainer'.show { display = 'split' }

Or use the commands RegexplainerShowSplit or RegexplainerShowPopup. RegexplainerHide and RegexplainerToggle are also available.

You can customize the popup window by specifying options.popup.border, which is a table of popup options from nui. Any options specified for options.popup will also override the defaults.

require'regexplainer'.show {
  display = 'popup',
  popup = {
    border = {
      padding = { 1, 2 },
      style = 'solid',
    },
  },
}

You could use this to, for example, set a different border based on the state of your editor.

Render Options

narrative.separator can also be a function taking the current component and returning a string clause separator. For example, to separate clauses by a new line, followed by > for each level of capture-group depth, define the following function:

narrative = {
  separator = function(component)
    local sep = '\n';
    if component.depth > 0 then
      for _ = 1, component.depth do
        sep = sep .. '> '
      end
    end
    return sep
  end
},

Input:

/zero(one(two(?<inner>three)))/;

Output:

`zero`  
capture group 1:  
> `one`  
> capture group 2:  
> > `two`  
> > named capture group 3 `inner`:  
> > > `three`

Yank

You can yank the regexplanation into any register with the yank function. The default register is ". This can be useful if you'd like to share the explanation of a regexp with your teammates, or if you'd like to report a mistake in regexplainer. The argument to yank is either a string (the register to yank to) or a table with register: string and options to show (e.g. mode = 'narrative', narrative = {}, etc.).

For example, to copy the regexplanation to your system clipboard, use either of these:

require'regexplainer'.yank'+'
require'regexplainer'.yank { register = '+' }

You can also use the command RegexplainerYank

:RegexplainerYank +

🗃️ TODO list

More Repositories

1

splitjoin.nvim

🪓🧷 Split or join list-like syntax constructs
Lua
76
star
2

stripe-elements

Custom Element Wrapper for Stripe.js v3 Elements
TypeScript
69
star
3

lit-css

Build Plugins for CSS tagged-template-literals
JavaScript
47
star
4

lazy-image

Lazily load your images with <lazy-image> custom element
HTML
45
star
5

rollup-plugin-lit-css

Moved to https://github.com/bennypowers/lit-css
35
star
6

service-worker

Custom Element for declaratively adding a service worker with "Click To Update" prompt and optional auto-install.
TypeScript
23
star
7

eleventy-plugin-slide-decks

🎼 It makes an itsy-bitsy, teeny-weeny, web-component slide deck prezzy 🎵 🎚️ Write slide decks with 11ty and share them over the web. 🎴
JavaScript
21
star
8

template-literal-comments.nvim

highlight languages embedded in ECMAScript template literals by adding a comment
Lua
15
star
9

rollup-plugin-modulepreload

Rollup plugin to add modulepreload links from generated chunks.
JavaScript
15
star
10

state

Lazy, explicit, typed, 1kb one-way state management
TypeScript
14
star
11

lit-css-loader

Webpack loader to load css files as lit-element tagged template literals
12
star
12

webc.nvim

WebC Support for NeoVim
Scheme
10
star
13

gnome-shell-extension-firefox-pip

Make Firefox Picture-in-Picture window Always on Top
JavaScript
9
star
14

dotfiles

Make yourself at home
Shell
8
star
15

shaka-player

Custom element wrapper for google's Shaka Player
JavaScript
6
star
16

template-instantiation-polyfill

A partial polyfill of the HTML Template Instantiation proposal
TypeScript
6
star
17

json-viewer

Custom Element that shows a JavaScript object's properties as syntax-highlighted JSON.
JavaScript
6
star
18

commitlint-gh-actions

JavaScript
5
star
19

cem-plugins

Custom Elements Manifest Analyzer Plugins
JavaScript
4
star
20

card

Simple card custom element with header and actions
TypeScript
3
star
21

changesets.nvim

Easily create changesets using your favourite editor
Lua
3
star
22

dev-feed

Web component that displays a feed for a dev.to user
JavaScript
3
star
23

svgo.nvim

Optimize SVGs in Neovim
Lua
2
star
24

mixins

Useful mixins for custom-element authors
TypeScript
2
star
25

power-pop

power-pop provides a brief animation indicating success or error.
HTML
2
star
26

starting-functional-javascript

A short slide deck on functional javascript
HTML
2
star
27

pluralize-behavior

Simple Polymer behavior that wraps pluralize
HTML
1
star
28

controller-host-color-picker

Color Picker Web Component With Reactive Controller
JavaScript
1
star
29

fire-behavior

🔥 Behavior which provides Polymer 2.0 elements with `fire`
HTML
1
star
30

minify-html-literals-static-html-repro

JavaScript
1
star
31

shul-tools

Synagogue Software - עם ישראל חי
TypeScript
1
star
32

controllers

TypeScript
1
star
33

exercism-kata

My solutions to various Exercism.io / coding interview kata.
Haskell
1
star
34

emoji-rating

Super Semantic Star Ratings with ⭐️ Emoji!
JavaScript
1
star
35

ecmascript-update

A Wee Catchup on the Language you Thought you Knew
JavaScript
1
star
36

fireblocks

Chonky Firefox tabs for square developers
CSS
1
star
37

emoji-checkbox

Super Semantic Checkbox with ✔️ Emoji!
JavaScript
1
star
38

cache-persist-client-args-repro

TypeScript
1
star
39

es-dev-server-response-transformers

A Library of Response Transformers for es-dev-server
TypeScript
1
star
40

backstage-web-components-example

screaming into the void: how to add a custom element in a backstage
TypeScript
1
star