{"id":13412907,"url":"https://github.com/bennypowers/nvim-regexplainer","last_synced_at":"2025-04-04T10:09:41.807Z","repository":{"id":41328118,"uuid":"460134121","full_name":"bennypowers/nvim-regexplainer","owner":"bennypowers","description":"Describe the regexp under the cursor","archived":false,"fork":false,"pushed_at":"2024-07-16T11:58:30.000Z","size":178,"stargazers_count":632,"open_issues_count":3,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T09:08:35.330Z","etag":null,"topics":["lua","neovim","neovim-plugin","nvim","nvim-plugin","regex","regexp","regular-expression","tree-sitter"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bennypowers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["bennypowers"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-02-16T18:45:09.000Z","updated_at":"2025-03-17T22:21:31.000Z","dependencies_parsed_at":"2024-04-12T06:02:32.389Z","dependency_job_id":"0204947c-b9ab-4270-a0c4-e31ebb36b137","html_url":"https://github.com/bennypowers/nvim-regexplainer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":"ellisonleao/nvim-plugin-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennypowers%2Fnvim-regexplainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennypowers%2Fnvim-regexplainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennypowers%2Fnvim-regexplainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennypowers%2Fnvim-regexplainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bennypowers","download_url":"https://codeload.github.com/bennypowers/nvim-regexplainer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157283,"owners_count":20893220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lua","neovim","neovim-plugin","nvim","nvim-plugin","regex","regexp","regular-expression","tree-sitter"],"created_at":"2024-07-30T20:01:30.911Z","updated_at":"2025-04-04T10:09:41.779Z","avatar_url":"https://github.com/bennypowers.png","language":"Lua","funding_links":["https://github.com/sponsors/bennypowers"],"categories":["Editing Support","Lua","nvim","Coding"],"sub_categories":["Scrollbar","Regex"],"readme":"![Am Yisrael Chai - עם ישראל חי](https://bennypowers.dev/assets/flag.am.yisrael.chai.png)\n\n# nvim-regexplainer\n\n![Lua][made-with-lua]\n![GitHub Workflow Status][build-status]\n[![Number of users on dotfyle][dotfyle-badge]][dotfyle]\n\nDescribe the regular expression under the cursor.\n\nhttps://user-images.githubusercontent.com/1466420/156946492-a05600dc-0a5b-49e6-9ad2-417a403909a8.mov\n\nHeavily inspired by the venerable [atom-regexp-railroad][atom-regexp-railroad].\n\n\u003e 👉 **NOTE**: Requires Neovim 0.7 👈\n\n## 🚚 Installation\n\n```lua\nuse { 'bennypowers/nvim-regexplainer',\n      config = function() require'regexplainer'.setup() end,\n      requires = {\n        'nvim-treesitter/nvim-treesitter',\n        'MunifTanjim/nui.nvim',\n      } }\n```\n\nYou need to install `regex` with `nvim-treesitter`, as well as the grammar for \nwhichever host language you're using. So for example if you wish to use \nRegexplainer with TypeScript sources, you need to do this:\n\n```vimscript\n:TSInstall regex typescript\n```\n\n## 🤔 Config\n\n```lua\n-- defaults\nrequire'regexplainer'.setup {\n  -- 'narrative'\n  mode = 'narrative', -- TODO: 'ascii', 'graphical'\n\n  -- automatically show the explainer when the cursor enters a regexp\n  auto = false,\n\n  -- filetypes (i.e. extensions) in which to run the autocommand\n  filetypes = {\n    'html',\n    'js',\n    'cjs',\n    'mjs',\n    'ts',\n    'jsx',\n    'tsx',\n    'cjsx',\n    'mjsx',\n  },\n\n  -- Whether to log debug messages\n  debug = false,\n\n  -- 'split', 'popup'\n  display = 'popup',\n\n  mappings = {\n    toggle = 'gR',\n    -- examples, not defaults:\n    -- show = 'gS',\n    -- hide = 'gH',\n    -- show_split = 'gP',\n    -- show_popup = 'gU',\n  },\n\n  narrative = {\n    indendation_string = '\u003e ', -- default '  '\n  },\n}\n```\n\n### `display`\n\nRegexplainer offers a small variety of display modes to suit your preferences.\n\n#### Split Window\n\nSet to `split` to display the explainer in a window below the editor.\nThe window will be reused, and has the filetype `Regexplainer`\n\n#### Popup Below Cursor\n\nSet to `popup` (the default) to display the explainer in a popup below the \ncursor. When the cursor moves, the popup closes. if `auto` is set, the popup \nwill automatically display whenever the cursor moves inside a regular expression\nYou can call `show` with your own display type to override your config\n\n```lua\nrequire'regexplainer'.show { display = 'split' }\n```\n\nOr use the commands `RegexplainerShowSplit` or `RegexplainerShowPopup`. \n`RegexplainerHide` and `RegexplainerToggle` are also available.\n\nYou can customize the popup window by specifying `options.popup.border`,\nwhich is a table of [popup options from nui][popup-options].\nAny options specified for `options.popup` will also override the defaults.\n\n```lua\nrequire'regexplainer'.show {\n  display = 'popup',\n  popup = {\n    border = {\n      padding = { 1, 2 },\n      style = 'solid',\n    },\n  },\n}\n```\n\nYou could use this to, for example, set a different border based on the state of \nyour editor.\n\n### Render Options\n\n`narrative.indendation_string` can be a function taking the current component and \nreturning an indendation indicator string. For example, to show the capture group on each line:\n\n```lua\nnarrative = {\n  indentation_string = function(component)\n    return component.capture_depth .. '\u003e  '\n  end\n},\n```\n\nInput:\n\n```javascript\n/zero(one(two(three)))/;\n```\n\nOutput: \n\n```markdown\n`zero`\ncapture group 1:\n1\u003e  `one`\n1\u003e  capture group 2:\n1\u003e  2\u003e  `two`\n1\u003e  2\u003e  capture group 3:\n1\u003e  2\u003e  3\u003e  `three`\n```\n\n## Yank\nYou can yank the regexplanation into any register with the `yank` function. The \ndefault register is `\"`. This can be useful if you'd like to share the \nexplanation of a regexp with your teammates, or if you'd like to report a \nmistake in regexplainer. The argument to `yank` is either a string (the register \nto yank to) or a table with `register: string` and options to `show` (e.g. `mode \n= 'narrative', narrative = {}`, etc.).\n\nFor example, to copy the regexplanation to your system clipboard, use either of \nthese:\n\n```lua\nrequire'regexplainer'.yank'+'\n```\n\n```lua\nrequire'regexplainer'.yank { register = '+' }\n```\n\nYou can also use the command `RegexplainerYank`\n\n```vim\n:RegexplainerYank +\n```\n\n## 🗃️  TODO list\n- [ ] Display Regexp [railroad diagrams][railroad-diagrams] using ASCII-art\n- [ ] Display Regexp [railroad diagrams][railroad-diagrams] via \n  [hologram][hologram] and [kitty image protocol][kitty], maybe with a sixel \n  fallback\n- [ ] online documentation\n- [x] some unit tests or something, i guess\n\n\n[made-with-lua]: https://img.shields.io/badge/Made%20with%20Lua-blueviolet.svg?style=for-the-badge\u0026logo=lua\n[build-status]: https://img.shields.io/github/actions/workflow/status/bennypowers/nvim-regexplainer/main.yml?branch=main\u0026label=tests\u0026style=for-the-badge\n[atom-regexp-railroad]: https://github.com/klorenz/atom-regex-railroad-diagrams/\n[popup-options]: https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/popup#border\n[railroad-diagrams]: https://github.com/tabatkins/railroad-diagrams/\n[hologram]: https://github.com/edluffy/hologram.nvim\n[kitty]: https://sw.kovidgoyal.net/kitty/graphics-protocol/\n[dotfyle]: https://dotfyle.com/plugins/bennypowers/nvim-regexplainer\n[dotfyle-badge]: https://dotfyle.com/plugins/bennypowers/nvim-regexplainer/shield?style=for-the-badge\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbennypowers%2Fnvim-regexplainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbennypowers%2Fnvim-regexplainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbennypowers%2Fnvim-regexplainer/lists"}