[
  {
    "path": ".editorconfig",
    "content": "root = true\n\n[*]\nend_of_line = LF\ninsert_final_newline = true\ntrim_trailing_whitespace = true\n\n[*.lua]\nindent_style = space\nindent_size = 4\n"
  },
  {
    "path": ".github/workflows/luarocks-release.yaml",
    "content": "name: LuaRocks release\non:\n  push:\n    tags: # Will upload to luarocks.org when a tag is pushed\n      - \"*\"\n  pull_request: # Will test a local install without uploading to luarocks.org\n\njobs:\n  luarocks-release:\n    runs-on: ubuntu-latest\n    name: LuaRocks upload\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v3\n      - name: LuaRocks Upload\n        uses: nvim-neorocks/luarocks-tag-release@v7\n        env:\n          LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}\n        with:\n          labels: |\n            neovim\n            yarepl.nvim\n"
  },
  {
    "path": ".gitignore",
    "content": ".tags\n.luarc.json\nscratch.lua\n.aider*\n.env\n.codex\n.nvim_log\n"
  },
  {
    "path": ".stylua.toml",
    "content": "column_width = 120\nline_endings = \"Unix\"\nindent_type = \"Spaces\"\nindent_width = 4\nquote_style = \"AutoPreferSingle\"\nno_call_parentheses = true\n"
  },
  {
    "path": "AGENTS.md",
    "content": "# Repository Guidelines\n\n## Project Structure & Module Organization\n\n- `lua/yarepl/` contains core plugin logic, REPL management, and built-in commands.\n- `lua/yarepl/extensions/` hosts optional integrations (aider, codex, code-cell, fzf, snacks).\n- `lua/telescope/_extensions/` provides the telescope REPL picker integration.\n- `extensions/README.md` documents extension usage and keymaps.\n- `assets/` stores screenshots used in the README.\n\n## Build, Test, and Development Commands\n\nThere is no build step; this is a Lua-based Neovim plugin.\n\n- Manual validation: open Neovim and `:Lazy load yarepl.nvim` or `:source` your config to test behavior.\n\n## Coding Style & Naming Conventions\n\n- Indentation: 4 spaces in Lua files (no tabs).\n- Lua modules are named by path (e.g., `require('yarepl.extensions.aider')`).\n- Prefer descriptive module/file names over abbreviations.\n- Keep new user-facing commands consistent with existing `REPL*` naming.\n\n## Testing Guidelines\n\n- No automated test suite is currently present.\n- If you add tests, document the framework and commands in this file and the README.\n\n## Commit & Pull Request Guidelines\n\n- Commit messages follow a Conventional Commits style, e.g., `feat: add option`, `fix: update logic`, `doc: update codex doc.`\n- PRs should include:\n  - A clear summary of behavior changes.\n  - Any relevant Neovim version requirements.\n  - Screenshots/GIFs for UI/UX changes (especially for picker or window behavior).\n\n## Agent-Specific Instructions\n\n- Follow `AGENTS.md` in the repo root for contributor guidance.\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Version 0.14.0 (2026-04-05)\n\n## Breaking Changes\n\n- **Lowercase `<Plug>` Keymaps**: Renamed `<Plug>(Yarepl-*)` mappings to\n  `<Plug>(yarepl-*)` to follow the more common Vim plugin convention of using\n  lowercase `<Plug>` names. This also applies to extension mappings such as\n  `<Plug>(yarepl-opencode-*)`.\n\n## Features\n\n- **OpenCode Extension**: a lightweight minimal extension for `opencode`.\n\n# Version 0.13.0 (2026-03-30)\n\n## Breaking Changes\n\n- **Unified Commands**: Replaced `REPL*`, `Codex*`, and `Aider*` commands with\n  a unified `Yarepl` command interface. Legacy commands remain functional but\n  show deprecation warnings.\n- **Unified Keymaps**: Replaced `<Plug>(REPL*)` keymaps with `<Plug>(yarepl-*)`\n  keymaps.\n\n## Features\n\n- **Telescope Extension**: Changed default action to `REPLFocus` for better\n  workflow.\n\n## Bug Fixes\n\n- **Send Operator**: Fixed handling of missing, empty, or inverted ranges for\n  the `send_operator` command.\n\n# Version 0.12.0 (2026-01-23)\n\n## Features\n\n- **REPLStartOrHideOrFocus**: Added a new command `REPLStartOrHideOrFocus` to\n  Toggles the visibility (focus/hide) of an existing REPL, or creates a new one\n  if it does not exist.\n- **Highlight Range**: Added an option to highlight the region sent to the REPL.\n- **Character-wise Sending**: Added support for sending character-wise regions to the REPL.\n- **Source Command Hint**: Added `show_source_command_hint` option to display\n  the first line of the source command as virtual text.\n- **Formatter**: Added `bracketed_pasting_delayed_cr` formatter for better\n  compatibility with REPLs like Claude Code and OpenAI Codex.\n- **Extensions (Codex/Aider)**:\n  - Added a new extension for OpenAI's Codex.\n  - Display the REPL name and ID in the winbar for the default `wincmd` in\n    Aider and Codex.\n  - Default floating window position changed to bottom-right corner.\n\n## Breaking Change\n\n- **REPLStart**: The semantics have changed. When a name is provided (e.g.,\n  `2REPLStart ipython`), the count now refers to the Nth _matching_ REPL, rather\n  than the global REPL ID. When the count is not provided, it now forces the\n  creation of a new REPL instance instead of focusing an existing REPL with ID\n  `1`.\n- **Config**: Removed `source_func` option. Use `source_syntax` instead, which\n  now accepts both string syntax values and functions.\n- **OS/Windows**: Renamed `os.windows.send_delayed_cr_after_sending` to\n  `os.windows.send_delayed_final_cr` to align with REPL meta options.\n- **Extensions**: Codex and Aider floating windows now default to the\n  bottom-right corner instead of occupying most of the screen.\n\n## Bug Fixes\n\n- **IPython Source**: Fixed temporary file handling in IPython source function\n  to allow proper PDB debugging context.\n\n# Version 0.11 (2025-04-08)\n\n## Features\n\n- Added command `REPLSourceOperator` and `REPLSourceVisual`\n  See [comparison in\n  README](https://github.com/milanglacier/yarepl.nvim?tab=readme-ov-file#replsourcevisual)\n  for a detailed comparison between `REPLSendVisual` and `REPLSourceVisual`.\n\n# Version 0.10.1 (2025-02-14)\n\n- Add luarocks release\n\n# Version 0.10 (2025-02-08)\n\n- Initial release\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "- [yarepl.nvim](#yareplnvim)\n- [Showcase](#showcase)\n- [Why yarepl.nvim?](#why-yareplnvim)\n- [Installation](#installation)\n- [Configuration](#configuration)\n  - [Setup](#setup)\n  - [Commands](#commands)\n    - [Yarepl start](#yarepl-start)\n    - [Yarepl start_or_focus_or_hide](#yarepl-start_or_focus_or_hide)\n    - [Yarepl attach_buffer](#yarepl-attach_buffer)\n    - [Yarepl detach_buffer](#yarepl-detach_buffer)\n    - [Yarepl cleanup](#yarepl-cleanup)\n    - [Yarepl focus](#yarepl-focus)\n    - [Yarepl hide](#yarepl-hide)\n    - [Yarepl hide_or_focus](#yarepl-hide_or_focus)\n    - [Yarepl close](#yarepl-close)\n    - [Yarepl swap](#yarepl-swap)\n    - [Yarepl send_visual](#yarepl-send_visual)\n    - [Yarepl source_visual](#yarepl-source_visual)\n    - [Yarepl send_line](#yarepl-send_line)\n    - [Yarepl send_operator](#yarepl-send_operator)\n    - [Yarepl source_operator](#yarepl-source_operator)\n    - [Yarepl exec](#yarepl-exec)\n  - [Keymaps](#keymaps)\n- [Window configuration](#window-configuration)\n- [Customizing REPLs](#customizing-repls)\n  - [Delayed Final CR Option](#delayed-final-cr-option)\n- [Customizing the Source Syntax](#customizing-the-source-syntax)\n- [Example keybinding setup](#example-keybinding-setup)\n- [Extensions](#extensions)\n  - [aider](#aider)\n  - [codex](#codex)\n  - [opencode](#opencode)\n  - [code-cell](#code-cell)\n  - [fzf-lua](#fzf-lua)\n  - [telescope](#telescope)\n  - [Snacks.picker](#snackspicker)\n- [Set up project-level REPLs](#set-up-project-level-repls)\n- [Create persistent REPLs in tmux](#create-persistent-repls-in-tmux)\n- [FAQ](#faq)\n  - [Why lazy loading with `lazy.nvim` doesn't work?](#why-lazy-loading-with-lazynvim-doesnt-work)\n  - [How do I avoid clutter from the bufferline plugin?](#how-do-i-avoid-clutter-from-the-bufferline-plugin)\n  - [Yarepl send_visual is not functioning properly](#yarepl-send_visual-is-not-functioning-properly)\n  - [`<Plug>(yarepl-send-visual)` Only Sends to First REPL](#plugyarepl-send-visual-only-sends-to-first-repl)\n- [Limitations](#limitations)\n- [Acknowledgements](#acknowledgements)\n\n**Breaking change:** `<Plug>` mappings now use lowercase `yarepl` names. If you\npreviously mapped `<Plug>(Yarepl-start)` or `<Plug>(Yarepl-codex-exec)`, update\nthem to `<Plug>(yarepl-start)` and `<Plug>(yarepl-codex-exec)`. This change\naligns with the common convention of using lowercase `<Plug>` names across Vim\nplugins. This change also takes effect immediately.\n\nThe old `REPL*` commands and `<Plug>(REPL*)` maps are now named under\n`Yarepl`. Use commands like `:Yarepl start`, `:Yarepl attach_buffer`,\n`:Yarepl send_visual`, and `:Yarepl exec`. The matching plug maps are named\nlike `<Plug>(yarepl-start)` and `<Plug>(yarepl-send-visual)`. The command part\nuses snake style, while `<Plug>` names use kebab style.\n\nThe legacy commands and keymaps (`REPL*`) still function for now, but they will\nbe removed on `2026-06-01`.\n\nIf you previously used `REPLStart`, `REPLSendVisual`, or\n`<Plug>(REPLStart-ipython)`, the replacement is the same idea with a different\nwrapper: `:Yarepl start`, `:Yarepl send_visual`, and\n`<Plug>(yarepl-start-ipython)`.\n\nThe unified `Yarepl` entry point keeps the plugin easier to extend and makes\ncompletion, counts, and future subcommands behave consistently instead of\nspreading the same actions across a growing list of top-level commands.\n\n# yarepl.nvim\n\nYet Another REPL is a flexible REPL / CLI App management tool that supports\nmultiple paradigms for interacting with them. This plugin also works with\nproject-level config and tmux, and includes native dot-repeat without requiring\nvim-repeat.\n\nFlexibility and parallelism are core priorities. With yarepl.nvim, you can\neffortlessly interact with multiple CLI Apps through various paradigms:\n\n- Send text from multiple buffers (same or different file types) to a single\n  REPL / CLI App.\n- Send text from a single buffer to multiple CLI Apps (same program or different)\n- Attach a buffer to a dedicated CLI Apps\n\nThe plugin features integration with `aider.chat`, `OpenAI Codex CLI`, and\n`OpenCode`, and provides convenient code cell text object definitions. Choose\nyour preferred\nfuzzy finder among `telescope`, `fzf-lua`, or `Snacks.picker` to preview active\nREPLs. These features are available as [extensions](#extensions).\n\n# Showcase\n\n![aider showcase](assets/aider-showcase.jpg)\n\nThis image highlights an AI-driven coding assistant and REPL,\n[aider.chat](https://aider.chat), managed by `yarepl`.\n\n![codex showcase](assets/codex-showcase.jpg)\n\nThis example showcases the Codex CLI integration running side by side with a\nNeovim buffer, all managed through `yarepl`.\n\n`yarepl` enables integration with the OpenAI's Codex CLI and Aider.chat. For\nmore details, refer to the [Extensions](#extensions) section.\n\n# Why yarepl.nvim?\n\nWith multiple projects at hand, I require the ability to send text from\ndifferent files to REPLs with the same type (such as multiple ipython REPLs).\n\nIn instances where I'm performing time-consuming tasks, but need to conduct\nfurther experimentation on the current file, I also require the capability to\nsend text from the same buffer to multiple REPLs.\n\nFurthermore, when conducting mixed-language programming in a literate\nprogramming style in text format such as `rmarkdown`, `quarto`, or plain\n`markdown`, I need to send text in the buffer to different REPLs such as R and\nPython .\n\nAdditionally, `yarepl.nvim` features a `source_syntax` capability that allows\nsourcing large code chunks from temporary files instead of sending them\ndirectly to the REPL. This prevents cluttering your interaction history and\nprovides better handling of substantial code content, especially useful on\nWindows where large stdin processing can be problematic. The plugin writes\nselected code regions/content to temporary files and provides convenient syntax\ndefinitions for how each REPL should source files.\n\nAs a CLI fnatic, to communicate with chatgpt, I prefer through a REPL `aichat`.\nAdditionally, I require a set of global hotkeys and an isolated REPL\nenvironment to facilitate communication with `aichat` separately without any\ninterference with other REPLs.\n\nUnfortunately, currently available REPL plugins do not afford me such great\nflexibility in managing REPL in multiple ways. This is why `yarepl.nvim` was\ncreated.\n\n# Installation\n\n`nvim 0.9` is required. Although `nvim 0.8` may also work, there are no plans\nto ensure backward compatibility with `nvim 0.8` if there are any compatibility\nissues.\n\n**lazy.nvim**:\n\n```lua\n{ 'milanglacier/yarepl.nvim', config = true }\n```\n\n**rocks.nvim**:\n\n`Yarepl` is available on luarocks.org. Simply run `Rocks install yarepl.nvim`\nto install it like any other luarocks package.\n\n`yarepl.nvim` does not require any dependencies but functions better with the following plugins:\n\n1. `telescope.nvim` or `fzf-lua`. `yarepl.nvim` provides extensions for REPL\n   previewer.\n\n2. A UI frontend that provides an alternative frontend for `vim.ui.select`.\n   Some options are `dressing.nvim` or `telescope-ui-select.nvim` (only one of\n   them needs to be installed).\n\n# Configuration\n\n## Setup\n\n```lua\n-- below is the default configuration, there's no need to copy paste them if\n-- you are satisfied with the default configuration, just calling\n-- `require('yarepl').setup {}` is sufficient.\nlocal yarepl = require 'yarepl'\n\nyarepl.setup {\n    -- see `:h buflisted`, whether the REPL buffer should be buflisted.\n    buflisted = true,\n    -- whether the REPL buffer should be a scratch buffer.\n    scratch = true,\n    -- the filetype of the REPL buffer created by `yarepl`\n    ft = 'REPL',\n    -- How yarepl open the REPL window, can be a string or a lua function.\n    -- See below example for how to configure this option\n    wincmd = 'belowright 15 split',\n    -- The available REPL palattes that `yarepl` can create REPL based on.\n    -- To disable a built-in meta, set its key to `false`, e.g., `metas = { R = false }`\n    metas = {\n        aichat = { cmd = 'aichat', formatter = 'bracketed_pasting', source_syntax = 'aichat' },\n        radian = { cmd = 'radian', formatter = 'bracketed_pasting_no_final_new_line', source_syntax = 'R' },\n        -- builtin command names search a .venv/bin/ipython first, then fall back to PATH\n        ipython = { cmd = 'builtin:ipython', formatter = 'bracketed_pasting', source_syntax = 'ipython' },\n        python = { cmd = 'builtin:python', formatter = 'trim_empty_lines', source_syntax = 'python' },\n        R = { cmd = 'R', formatter = 'trim_empty_lines', source_syntax = 'R' },\n        bash = {\n            cmd = 'bash',\n            formatter = vim.fn.has 'linux' == 1 and 'bracketed_pasting' or 'trim_empty_lines',\n            source_syntax = 'bash',\n        },\n        zsh = { cmd = 'zsh', formatter = 'bracketed_pasting', source_syntax = 'bash' },\n    },\n    -- when a REPL process exits, should the window associated with those REPLs closed?\n    close_on_exit = true,\n    -- whether automatically scroll to the bottom of the REPL window after sending\n    -- text? This feature would be helpful if you want to ensure that your view\n    -- stays updated with the latest REPL output.\n    scroll_to_bottom_after_sending = true,\n    -- Format REPL buffer names as #repl_name#n (e.g., #ipython#1) instead of using terminal defaults\n    format_repl_buffers_names = true,\n    -- Highlight the operated range when using send/source operators\n    highlight_on_send_operator = { enabled = false, hl_group = 'IncSearch', timeout = 150 },\n    os = {\n        -- Some hacks for Windows. macOS and Linux users can simply ignore\n        -- them. The default options are recommended for Windows user.\n        windows = {\n            -- Send a final `\\r` to the REPL with delay,\n            send_delayed_final_cr = true,\n        },\n    },\n    -- Display the first line as virtual text to indicate the actual\n    -- command sent to the REPL.\n    source_command_hint = {\n        enabled = false,\n        hl_group = 'Comment',\n    },\n}\n```\n\n## Commands\n\n`yarepl` doesn't set any default keybindings. Instead, it offers a variety of\ncommands that you can use to create your own keybindings. We'll also provide an\nexample configuration for keybindings based on these commands. Additionally,\n`yarepl` provides a collection of `<Plug>` keymaps, which you can bind them to\nyour favorite mappings.\n\nHere is a list of available commands:\n\n### Yarepl start\n\nCreates a REPL with id `i` from the list of available REPLs.\n\nYou can create a REPL with a specific id by providing a count, such as\n`3Yarepl start` for a REPL with id `3`. If no count is provided, a new REPL\nwith increamental ID will be created. You can also provide a name as an\nargument. If no argument is given, you'll be prompted to select a REPL from the\nlist of available ones. If the id is already in use, it will focus on the REPL\nwith that id.\n\nWhen a name is provided and a count is also provided (for example, `2Yarepl\nstart ipython`), the count selects the Nth REPL with that name. If there are\nfewer than N existing REPLs with that name, a new one is created. When a name\nis provided without a count (`Yarepl start ipython`), it always creates a new\nREPL of that name.\n\nIf you append a `!` to the command, the current buffer will attach to the newly\ncreated REPL, for instance, `Yarepl start!` or `3Yarepl start!`. Note that\nattachment only happens when a new REPL is created.\n\n### Yarepl start_or_focus_or_hide\n\nToggles the visibility (focus/hide) of an existing REPL, or creates a new one\nif it does not exist.\n\nThe rules for counts and optional REPL names mirror those of `Yarepl start`,\nincluding named selection logic like `2Yarepl start_or_focus_or_hide ipython`.\n\nHere are examples of how to use this command:\n\n1. `Yarepl start_or_focus_or_hide` will hide or focus REPL 1 when it exists,\n   otherwise it creates a new REPL.\n\n2. `Yarepl start_or_focus_or_hide ipython` will hide or focus the first\n   `ipython` REPL, otherwise it creates a new `ipython` REPL.\n\n3. `3Yarepl start_or_focus_or_hide` will hide or focus REPL 3 when it exists,\n   otherwise it creates a new REPL.\n\n4. `3Yarepl start_or_focus_or_hide ipython` will hide or focus the 3rd\n   `ipython` REPL, otherwise it creates a new `ipython` REPL.\n\n**Important difference**: without a count, `Yarepl start` always attempts to\nstart a new REPL, whereas `Yarepl start_or_focus_or_hide` first attempts to\nfocus/hide an existing REPL and creates a new one only if none is found.\n\n### Yarepl attach_buffer\n\nAttaches the current buffer to REPL `i`, for instance, `3Yarepl attach_buffer`\nwill attach the current buffer to REPL 3. If no count is provided, you'll be\nprompted to select the REPL you want to attach the current buffer to. If you\nadd a trailing `!`, it will attempt to detach the current buffer from any REPL.\n\n### Yarepl detach_buffer\n\nDetach current buffer from any REPL.\n\n### Yarepl cleanup\n\nCleans up any invalid REPLs and rearranges the sequence of REPL ids. Usually,\nthere's no need to use this command manually since invalid REPLs are cleaned up\nautomatically at the appropriate time.\n\n### Yarepl focus\n\nFocuses on REPL `i` or the REPL that the current buffer is attached to.\n\nYou can provide an optional argument, and the function will attempt to focus on\nthe closest REPL with the specified name. If no count is supplied, it will try\nto focus on the REPL that the current buffer is attached to. If the current\nbuffer isn't attached to any REPL, it will use REPL 1. If you add a count `i`,\nit will focus on the REPL `i`.\n\nHere are some examples of how to use this command:\n\n1. `Yarepl focus` will try to focus on the REPL that the current buffer is\n   attached to. If the current buffer isn't attached to any REPL, it will use\n   REPL 1.\n\n2. `Yarepl focus ipython` will try to focus on the closest REPL with the name\n   `ipython` starting from id `1`.\n\n3. `3Yarepl focus` will focus on REPL 3.\n\n4. `3Yarepl focus ipython` will try to focus on the closest REPL with the name\n   `ipython` starting from id `3`.\n\n### Yarepl hide\n\nHides REPL `i` or the REPL that the current buffer is attached to.\n\nIf you provide an optional argument, the function will attempt to hide the\nclosest REPL with the specified name. When no count is supplied, it will try to\nhide the REPL that the current buffer is attached to. If the current buffer\nisn't attached to any REPL, it will use REPL 1. If you add a count `i`, it\nwill hide REPL `i`.\n\nHere are examples of how to use this command:\n\n1. `Yarepl hide` will try to hide the REPL that the current buffer is attached\n   to. If the current buffer isn't attached to any REPL, it will use REPL 1.\n\n2. `Yarepl hide ipython` will try to hide the closest REPL with the name\n   `ipython` starting from id `1`.\n\n3. `3Yarepl hide` will hide REPL 3.\n\n4. `3Yarepl hide ipython` will try to hide the closest REPL with the name\n   `ipython` starting from id `3`.\n\n### Yarepl hide_or_focus\n\nHides or focuses on REPL `i` or the REPL that the current buffer is attached\nto.\n\nIf you provide an optional argument, the function will attempt to hide or\nfocus on the closest REPL with the specified name. When no count is supplied,\nit will try to hide or focus on the REPL that the current buffer is attached to.\nIf the current buffer isn't attached to any REPL, it will use REPL 1. If you\nadd a count `i`, it will hide REPL `i`.\n\nHere are examples of how to use this command:\n\n1. `Yarepl hide_or_focus` will try to hide or focus on the REPL that the\n   current buffer is attached to. If the current buffer isn't attached to any\n   REPL, it will use REPL 1.\n\n2. `Yarepl hide_or_focus ipython` will try to hide or focus on the closest\n   REPL with the name `ipython` starting from id `1`.\n\n3. `3Yarepl hide_or_focus` will hide or focus on REPL 3.\n\n4. `3Yarepl hide_or_focus ipython` will try to hide or focus on the closest\n   REPL with the name `ipython` starting from id `3`.\n\n### Yarepl close\n\nCloses REPL `i` or the REPL that the current buffer is attached to.\n\nIf you provide an optional argument, the function will attempt to close the\nclosest REPL with the specified name. If no count is supplied, it will try to\nclose the REPL that the current buffer is attached to. If the current buffer\nisn't attached to any REPL, it will use REPL 1. If you add a count `i`, it\nwill close REPL `i`.\n\nHere are examples of how to use this command:\n\n1. `Yarepl close` will try to close the REPL that the current buffer is\n   attached to. If the current buffer isn't attached to any REPL, it will use\n   REPL 1.\n\n2. `Yarepl close ipython` will try to close the closest REPL with the name\n   `ipython` and starting from id `1`.\n\n3. `3Yarepl close` will close REPL 3.\n\n4. `3Yarepl close ipython` will try to close the closest REPL with the name\n   `ipython` starting from id `3`.\n\n### Yarepl swap\n\nSwaps two REPLs. If no REPL ID is provided, you'll be prompted to select both\nREPLs. If you provide one REPL ID, you'll be prompted to select the second\nREPL.\n\n### Yarepl send_visual\n\nSends the visual range to REPL `i` or the REPL that the current buffer\nis attached to.\n\nIf you provide an optional argument, the function will attempt to send to the\nclosest REPL with the specified name. When no count is supplied, it first\nchecks whether the current buffer is attached to a REPL with that name and uses\nit. If the buffer isn't attached to a matching REPL, it will use REPL 1 to\nfind the closest match. If you add a count `i`, it will send to the closest\nREPL with that name relative to `i`.\n\nOptional highlighting for the operated range is available for both\n`Yarepl send_operator` and `Yarepl source_operator` by setting\n`highlight_on_send_operator.enabled = true` in your setup.\n\nHere are examples of how to use this command:\n\n1. `Yarepl send_visual` sends the visual range to the REPL that the current\n   buffer is attached to. If the buffer is not attached to any REPL, it uses\n   REPL 1.\n\n2. `3Yarepl send_visual` sends the visual range to REPL 3.\n\n3. `Yarepl send_visual ipython` sends the visual range to the attached ipython\n   REPL if there is one for the current buffer; otherwise, it uses the closest\n   ipython REPL relative to id `1`.\n\n4. `3Yarepl send_visual ipython` sends the visual range to the closest ipython\n   REPL relative to id `3`.\n\nNote that due to a limitation of vim, when using `Yarepl send_visual` via\ncmdline rather than in a keymap, you must press `Control+u` before using the\ncommand. For example, `V3j:<Control+u>3Yarepl send_visual` sends the selected\nthree lines to REPL `3`. However, you do not need to specify `Control+u` in\nyour keymap as the function will do this for you.\n\n### Yarepl source_visual\n\nSimilar to `Yarepl send_visual`, the key distinction with `Yarepl source_visual`\nis that it first writes the visually selected code to a temporary file. It then\nsends a one-liner command to the REPL to source this file, instead of sending\nthe content directly.\n\nThe primary advantage of `Yarepl source_visual` lies in handling large code\ncontent. Instead of sending huge code chunks directly to the REPL, it prevents\ncluttering your interaction history, maintaining a cleaner session.\nAdditionally, on Windows, sourcing from a file mitigates potential issues with\nstdin processing when the REPL must read substantial input, as the file-based\napproach significantly reduces the data read from the stdin.\n\nHowever, one notable drawback involves the security implications of temporary\nfile creation. Since the REPL executes code from this file, any vulnerability\nin temporary file handling, such as exposure to malicious attack, could pose\nsecurity risks. Thus, while beneficial in certain scenarios, this method\nrequires careful consideration of its potential drawbacks.\n\nNote that the REPL configuration requires a corresponding `source_syntax`\nimplementation. For more information, refer to the section [Customizing the\nSource Syntax](#customizing-the-source-syntax). Built-in source\nimplementations are available for Python, R, and Bash.\n\nConsider enabling `config.source_command_hint.enabled = true`. When enabled,\nthe first non-empty line of the code chunk displays as virtual text alongside\nthe source command sent to the REPL, providing a useful hint about the actual\ncommand being executed.\n\n### Yarepl send_line\n\nSends current line to REPL `i` or the REPL that current buffer is attached to.\n\nIf you provide an optional argument, the function will attempt to send to the\nclosest REPL with the specified name. When no count is supplied, it first\nchecks whether the current buffer is attached to a REPL with that name and uses\nit. If the buffer isn't attached to a matching REPL, it will use REPL 1 to\nfind the closest match. If you add a count `i`, it will send to the closest\nREPL with that name relative to `i`.\n\nHere are examples of how to use this command:\n\n1. `Yarepl send_line` sends the current line to the REPL that the current\n   buffer is attached to. If the buffer is not attached to any REPL, it uses\n   REPL 1.\n\n2. `3Yarepl send_line` sends the current line to REPL 3.\n\n3. `Yarepl send_line ipython` sends the current line to the attached ipython\n   REPL if there is one for the current buffer; otherwise, it uses the closest\n   ipython REPL relative to id `1`.\n\n4. `3Yarepl send_line ipython` sends the current line to the closest ipython\n   REPL relative to id `3`.\n\n### Yarepl send_operator\n\nThe operator to send the text to REPL `i` or the REPL that the current buffer\nis attached to.\n\nIf you provide an optional argument, the function will attempt to send to the\nclosest REPL with the specified name. When no count is supplied, it first\nchecks whether the current buffer is attached to a REPL with that name and uses\nit. If the buffer isn't attached to a matching REPL, it will use REPL 1 to\nfind the closest match. If you add a count `i`, it will send to the closest\nREPL with that name relative to `i`.\n\nHere are examples of how to use this command:\n\n1. `Yarepl send_operator` acts as the operator to send the text to the REPL\n   that the current buffer is attached to. If the buffer is not attached to any\n   REPL, it uses REPL 1.\n\n2. `3Yarepl send_operator` sends the motion to REPL 3.\n\n3. `Yarepl send_operator ipython` sends the motion to the attached ipython REPL\n   if there is one for the current buffer; otherwise, it uses the closest\n   ipython REPL relative to id `1`.\n\n4. `3Yarepl send_operator ipython` sends the motion to the closest ipython\n   REPL relative to id `3`.\n\n`Yarepl send_operator` is **dot-repeatable**, you do not need to install\nvim-repeat to make it work.\n\n### Yarepl source_operator\n\nThe `Yarepl source_operator` is analogous to the `Yarepl send_operator`. To\nunderstand the distinction between these two operators, refer to the section on\n`Yarepl source_visual`, which contrasts `Yarepl send_visual` with\n`Yarepl source_visual`. This comparison provides a clear analogy that\nhighlights the differences between `Yarepl send_operator` and\n`Yarepl source_operator`.\n\n### Yarepl exec\n\nSends the command typed in the cmdline to REPL `i` or the REPL that the current\nbuffer is attached to.\n\nIf the first argument of this command is `$NAME`, the function will attempt to\nsend to a REPL with the specified `NAME`. If no count is supplied, it first\nchecks whether the current buffer is attached to a REPL with that name and uses\nit. If the buffer isn't attached to a matching REPL, it will use REPL 1 to\nfind the closest match. If you add a count `i`, it will send to the closest\nREPL with that name relative to `i`.\n\nHere are examples of how to use this command:\n\n1. `Yarepl exec %run a_file.py` will send the command `%run a_file.py` to the\n   REPL 1.\n\n2. `3Yarepl exec print(\"hello world\")` will send the command `print(\"hello\nworld\")` to the REPL 3.\n\n3. `Yarepl exec $ipython %whos` will send the command `%whos` to the closest\n   ipython REPL relative to id 1.\n\n4. `Yarepl exec $ipython %whos` will send the command `%whos` to the closest\n   ipython REPL relative to id 3.\n\n5. `Yarepl exec print(\"hello world\")^Mprint(\"hello world again\")` will send the\n   following two lines to the REPL current buffer is attached to or REPL 1.\n\n```python\nprint(\"hello world\")\nprint(\"hello world again\")\n```\n\nNote:\n\n1. To type a **literal** `<Enter>` (`^M`) in `cmdline`, you must press\n   `<Ctrl-v> <Enter>` rather than directly type `Enter`.\n\n2. Some neovim command will interpolate `%` to the file name of current buffer.\n   But `Yarepl exec` will not do this for you. The interpolation only happens for\n   the first `$` to get the desired `REPL` name.\n\n## Keymaps\n\n`yarepl` provides the following keymaps:\n\n- `<Plug>(yarepl-start)`\n- `<Plug>(yarepl-start-or-focus-or-hide)`\n- `<Plug>(yarepl-focus)`\n- `<Plug>(yarepl-hide)`\n- `<Plug>(yarepl-hide-or-focus)`\n- `<Plug>(yarepl-send-line)`\n- `<Plug>(yarepl-send-operator)`\n- `<Plug>(yarepl-send-visual)`\n- `<Plug>(yarepl-source-operator)`\n- `<Plug>(yarepl-source-visual)`\n- `<Plug>(yarepl-close)`\n- `<Plug>(yarepl-exec)`\n\nThe keymap variant behaves exactly the same as its command variant. For\nexample, you map `<Leader>s` to `<Plug>(yarepl-start)`, then type `<Leader>s`\nis equivalent to `:Yarepl start`. Type `3<Leader>s` is equivalent to\n`:3Yarepl start`.\n\nAnd for each meta you registered (say you have a meta named `ipython`), the following keymaps will be registered:\n\n- `<Plug>(yarepl-start-ipython)`\n- `<Plug>(yarepl-start-or-focus-or-hide-ipython)`\n- `<Plug>(yarepl-focus-ipython)`\n- `<Plug>(yarepl-hide-ipython)`\n- `<Plug>(yarepl-hide-or-focus-ipython)`\n- `<Plug>(yarepl-send-line-ipython)`\n- `<Plug>(yarepl-send-operator-ipython)`\n- `<Plug>(yarepl-send-visual-ipython)`\n- `<Plug>(yarepl-source-operator-ipython)`\n- `<Plug>(yarepl-source-visual-ipython)`\n- `<Plug>(yarepl-close-ipython)`\n- `<Plug>(yarepl-exec-ipython)`\n\nFor keymaps with a meta, as you would expected, say you bind `<LocalLeader>s`\nto `<Plug>(yarepl-start-ipython)`, then type `<LocalLeader>s` is equivalent to\n`:Yarepl start ipython`. Type `3<LocalLeader>s` is equivalent to\n`:3Yarepl start ipython`.\n\nNote that any letters that are not alphanumeric or `-`/`_` will be replaced\nwith `-`. Say you have a meta named `python a`, the corresponding keymap to\naccess them will be `<Plug>(yarepl-start-python-a)`.\n\nWhen you are binding those plug keymaps to your own keybindings, make sure this is\na recursive map. e.g. `vim.keymap.set('n', '<Plug>(yarepl-start-ipython)', { noremap = false })`.\n\n# Window configuration\n\nif `wincmd` is a string, `yarepl` will execute it as a vimscript command.\n\n```lua\nwincmd = 'belowright 15 split'\n-- will create a horizontal split below the current using window and takes up 15 lines for the new window\nwincmd = 'vertical 30 split'\n-- will create a vertical split right to the current using window and takes up 30 columns for the new window\n```\n\nIn addition to passing a string to `wincmd`, you can also pass a Lua function.\nThis function accepts two parameters: the buffer number of the REPL buffer, and\nthe name of the REPL (the keys of `metas`).\n\n```lua\nwincmd = function(bufnr, name)\n    vim.api.nvim_open_win(bufnr, true, {\n        relative = 'editor',\n        row = math.floor(vim.o.lines * 0.25),\n        col = math.floor(vim.o.columns * 0.25),\n        width = math.floor(vim.o.columns * 0.5),\n        height = math.floor(vim.o.lines * 0.5),\n        style = 'minimal',\n        title = name,\n        border = 'rounded',\n        title_pos = 'center',\n    })\nend\n```\n\nThis function creates a floating window at the center of the Vim screen with\nspecific size and styling.\n\nYou can further customize the behavior by applying the `wincmd` configuration\nto specific `meta` entries. When a `meta` includes its own `wincmd` setting, it\noverrides the global `wincmd`.\n\n```lua\n\nfloat_wincmd = function(bufnr, name)\n    vim.api.nvim_open_win(bufnr, true, {\n        relative = 'editor',\n        row = math.floor(vim.o.lines * 0.25),\n        col = math.floor(vim.o.columns * 0.25),\n        width = math.floor(vim.o.columns * 0.5),\n        height = math.floor(vim.o.lines * 0.5),\n        style = 'minimal',\n        title = name,\n        border = 'rounded',\n        title_pos = 'center',\n    })\nend\n\nyarepl.setup {\n    metas = {\n        -- REPL local settings\n        ipython = { wincmd = 'topleft 25 split' },\n        radian = { wincmd = float_wincmd },\n    }\n    -- global settings\n    wincmd = 'belowright 15 split',\n}\n```\n\nSimilar to `wincmd` (which allows you to configure a global default with\nmeta-local overrides), you can also set meta-local overrides for\n`source_command_hint`. The configuration option name for meta-local overrides\nis identical to the global setting.\n\n# Customizing REPLs\n\nYou can disable a built-in REPL meta by set the key to `false`:\n\n```lua\nmetas = {\n    R = false\n}\n```\n\nTo modify a built-in meta's settings, simply override the specific option.\nThere's no need to copy the default values for other options:\n\n```lua\nmetas = {\n    ipython = { cmd = { 'ipython', '--simple-prompt' } }\n}\n```\n\nThe built-in command names `builtin:ipython` and `builtin:python` look for\n`.venv/bin` on Unix-like systems or `.venv/Scripts` on Windows before falling\nback to the executable on `PATH`.\n\nYou can add your own REPL meta by following this example:\n\n```lua\nfunction send_line_verbatim(lines)\n    -- each line is a string\n    return lines\nend\n\nfunction ipython_or_python()\n    -- find_binary searches upward from the current directory until it finds the binary\n    -- search_root: relative path to search (e.g., \".venv/bin\")\n    -- binary_name: executable to locate (e.g., \"ipython\")\n    -- fallback_binary: returned if no match is found (e.g., 'ipython' from PATH)\n    local ipython_cmd = yarepl.cmd_builtin.find_binary(\".venv/bin\", \"ipython\", 'ipython')\n\n    if vim.fn.executable(ipython_cmd) == 1 then\n        return { ipython_cmd, '--simple-prompt' }\n    end\n\n    -- Fall back to python3 using the same search logic\n    return yarepl.cmd_builtin.find_binary(\".venv/bin\", \"python3\", 'python3')\nend\n\nfunction ipython_or_python_formatter(lines)\n    if vim.fn.executable 'ipython' == 1 then\n        return yarepl.formatter.bracketed_pasting(lines)\n    else\n        return yarepl.formatter.trim_empty_lines(lines)\n    end\nend\n\nmetas = {\n    ipython_new = { cmd = { 'ipython', '--simple-prompt' }, formatter = send_line_verbatim },\n    ipython_or_python = { cmd = ipython_or_python, formatter = ipython_or_python_formatter },\n}\n\n```\n\n`cmd` can be three types: a string, a list of strings, or a function that\nreturns either a string or list of strings. It can also be one of yarepl's\nbuiltin command names, such as `builtin:ipython` or `builtin:python`.\n\nIf you want to build your own path lookup logic, use\n`require('yarepl').cmd_builtin.find_binary(search_root, binary_name, fallback_binary)`\ninside a custom `cmd` function. The helper searches upward from the current\ndirectory for `search_root/binary_name` and returns `fallback_binary` when no\nmatching binary is found.\n\n`formatter` can be either:\n\n1. A string that matches a builtin formatter name:\n   - `bracketed_pasting`: wrap the content within bracketed paste sequences\n   - `bracketed_pasting_no_final_new_line`: similar to `bracketed_pasting`, but does not add a new line at the end\n   - `bracketed_pasting_delayed_cr`: similar to `bracketed_pasting`, but use with `send_delayed_final_cr = true`\n   - `trim_empty_lines`: remove empty lines from the input\n2. A function that takes a list of strings as input and returns a list of\n   strings to send to the REPL\n\n[Here is a more complex example for ghci, a haskell repl.](https://github.com/milanglacier/yarepl.nvim/issues/21)\n\n`yarepl` offers a convenient helper function that simplifies the process of\ncreating a custom formatter without starting from scratch. For usage examples\nand general guidelines on setting your own REPL formatter, expand the\n**Details** section below.\n\n<details>\n\nSome REPLs can distinguish between pasted text and text from the user manual\ninput by using prefix and suffix sequences, such as bracketed paste.\n\nFor modern REPLs with bracketed pasting support (which is usually the case), it\nis recommended to use \"`bracketed_pasting`\"\n\nHere are some tips for writing your own formatter function:\n\n1. You may want to add a new entry `\"\\r\"` at the end of the list to indicate\n   the end of input.\n\n2. If your REPL cannot distinguish between copy-pasted text and text from user\n   manual input, you may want to replace `\\t` with 4 or 8 spaces since sending\n   a raw `\\t` may be interpreted as invoking completion.\n\n3. Do not include `\\n` in any line as the `chansend` function will\n   automatically replace it with `\\0`.\n\n4. You may want to remove any empty lines from the input (a list of strings)\n   since `chansend` function translates an empty string `\"\"` into `\"\\n\"`. For\n   some REPLs without bracketed pasting support (such as Python), a plain\n   `\"\\n\"` may be treated as the end of input, blocking the rest of the code in\n   the same function.\n\n5. If your REPL cannot distinguish between copy-pasted text and text from user\n   manual input and your REPL will do auto-indent for you, you may want to\n   remove any leading spaces from each line to prevent double indentation.\n\n6. The returned list of strings will be sent to the `chansend` function for\n   reference.\n\n```lua\n-- Calling this function will return a function that takes a list of strings as\n-- input and returns a list of strings. This can be used as the formatter function\n-- of meta.\n\n-- these are the default config\nyarepl.formatter.factory {\n    -- Specifies whether to return tabs in the string as spaces.\n    replace_tab_by_space = false,\n    -- Specifies the number of spaces to replace the tab (if enabled).\n    number_of_spaces_to_replace_tab = 8,\n    -- For a list of strings containing more than one string:\n    when_multi_lines = {\n        -- The prefixing code sent to the repl firstly.\n        open_code = '',\n        -- The suffixing code sent to the repl finally.\n        end_code = '\\r',\n        -- Whether to remove empty lines from the list of strings.\n        trim_empty_lines = false,\n        -- Whether to remove leading spaces at the beginning of each line.\n        remove_leading_spaces = false,\n        -- If gsub_pattern and gsub_repl are not empty, `string.gsub` will\n        -- be called with `gsub_pattern` and `gsub_repl` on each line. Note\n        -- that you should use Lua pattern instead of Vim regex pattern.\n        -- The gsub calls happen after `trim_empty_lines`,\n        -- `remove_leading_spaces`, and `replace_tab_by_space`, and before\n        -- prepending and appending `open_code` and `end_code`.\n        gsub_pattern = '',\n        gsub_repl = '',\n    },\n    -- For a list containing only one string:\n    when_single_line = {\n        -- The prefixing code sent to the repl firstly.\n        open_code = '',\n        -- The suffixing code sent to the repl finally.\n        end_code = '\\r',\n        -- the same as the specs of `when_multi_lines`\n        gsub_pattern = '',\n        gsub_repl = '',\n    },\n    os = {\n        -- Some hacks for Windows. macOS and Linux users can simply ignore\n        -- them. The default options are recommended for Windows user.\n        windows = {\n            -- Join the lines with `\\r` before sending to REPL.\n            join_lines_with_cr = true,\n        },\n    },\n}\n\n-- `yarepl` provides four builtin formatters that can be referenced by name:\n-- 1. 'bracketed_pasting' - Uses bracketed paste mode for modern REPLs\n-- 2. 'bracketed_pasting_no_final_new_line' - Same as above but without final newline\n-- 3. 'bracketed_pasting_delayed_cr': similar to `bracketed_pasting`, but use with `send_delayed_final_cr = true`\n-- 4. 'trim_empty_lines' - Trims empty lines from input\n\n-- You can also create custom formatters by calling `yarepl.formatter.factory`:\n\nyarepl.formatter.trim_empty_lines = yarepl.formatter.factory {\n    when_multi_lines = {\n        trim_empty_lines = true,\n        remove_leading_spaces = false,\n    },\n}\n\nyarepl.formatter.bracketed_pasting = yarepl.formatter.factory {\n    when_multi_lines = {\n        open_code = '\\27[200~',\n        end_code = '\\27[201~\\r',\n        trim_empty_lines = false,\n        remove_leading_spaces = false,\n    },\n}\n```\n\n</details>\n\n## Delayed Final CR Option\n\n`send_delayed_final_cr` (optional, defaults to `false`): Some REPLs do not\nrecognize the final CR (return)'s purpose is to tell the REPL that we want to\n\"finalize\" (or evaluate) that command when it is input with a large chunk of\ntext when bracketed pasting is enabled. To mitigate this, we have to send the\nfinal CR with a delay (to let the REPL realize that we want to evaluate that\ncommand). In general we should ignore this option (keep it as the default\n`false`). When you do enable this option, prefer using the\n`bracketed_pasting_delayed_cr` formatter so that the final CR is not included\nin the initial stream (it will be sent by the delayed event). The observed\nexceptions are Claude Code, Codex, and Opencode which should use `true`. PRs\nare welcome if you find other REPLs that require setting this option to `true`.\n\nExample usage:\n\n```lua\nmetas = {\n    claude_code = {\n        cmd = 'claude',\n        formatter = 'bracketed_pasting_delayed_cr',\n        source_syntax = '@{{file}}',\n        send_delayed_final_cr = true\n    },\n    ipython = {\n        cmd = 'ipython',\n        formatter = 'bracketed_pasting',\n        send_delayed_final_cr = false  -- this is the default, can be omitted\n    },\n    -- yarepl provides builtin extension to use with codex.\n    codex = require('yarepl.extensions.codex').create_codex_meta(),\n}\n```\n\n# Customizing the Source Syntax\n\nTo utilize `Yarepl source_operator` and `Yarepl source_visual`, your REPL meta\nconfiguration must include either `source_syntax`.\n\nHere's an example setup using `yarepl` with a source syntax:\n\n```lua\nlocal yarepl = require 'yarepl'\n\nyarepl.setup {\n    metas = {\n        radian = {\n            cmd = 'radian',\n            formatter = 'bracketed_pasting_no_final_new_line',\n            source_syntax = 'eval(parse(text = \"{{file}}\"))',\n        },\n    }\n}\n```\n\nWhen `source_syntax` is specified, the selected code content is initially\nwritten to a temporary file. Here, `{{file}}` serves as a placeholder, which is\nreplaced by the temporary file path. The interpolated string is subsequently\nsent to the REPL.\n\nSeveral built-in `source_syntax` options can be accessed as strings: `R`,\n`aichat`, `bash`, `ipython` and `python`.\n\nFor a more flexible \"sourcing\" behavior, you can also define `source_syntax` as\na function, instead of using a string with `{{file}}`. This function must take\na string and return a string. The input is the selected code, and the output is\nwhat gets sent to the REPL.\n\nA common approach involves writing the input string to a temporary file, then\nreturning a string that sources this file. The exact \"sourcing\" syntax depends\non the target programming language.\n\nHere's an example setup using `yarepl` with a source function:\n\n<details>\n\n```lua\nlocal yarepl = require 'yarepl'\nlocal python_source_func = function(str)\n    local file = make_tmp_file(str)\n    if not file then\n        return\n    end\n\n    local cmd = string.format('exec(open(\"%s\", \"r\").read())', file)\n    return cmd\nend\n\n\nyarepl.setup {\n    metas = {\n        ipython = {\n            cmd = 'ipython',\n            formatter = 'bracketed_pasting',\n            source_syntax = python_source_func,\n        },\n    }\n}\n```\n\n</details>\n\n# Example keybinding setup\n\nIf you don't want to use those `<Plug>` keymaps provided by the plugin but\ninstead want to build the keymaps by your own, please check the\n[wiki.](https://github.com/milanglacier/yarepl.nvim/wiki/Example-Keymap-setup-without-using-%60-Plug-%60)\n\nHere is the keybindings setup from the maintainer:\n\n```lua\nlocal keymap = vim.api.nvim_set_keymap\nlocal bufmap = vim.api.nvim_buf_set_keymap\n\nkeymap('n', '<Leader>cs', '<Plug>(yarepl-start-aichat)', {\n    desc = 'Start an Aichat REPL',\n})\nkeymap('n', '<Leader>cf', '<Plug>(yarepl-focus-aichat)', {\n    desc = 'Focus on Aichat REPL',\n})\nkeymap('n', '<Leader>ch', '<Plug>(yarepl-hide-aichat)', {\n    desc = 'Hide Aichat REPL',\n})\nkeymap('v', '<Leader>cr', '<Plug>(yarepl-send-visual-aichat)', {\n    desc = 'Send visual region to Aichat',\n})\nkeymap('v', '<Leader>cR', '<Plug>(yarepl-source-visual-aichat)', {\n    desc = 'Source visual region to Aichat',\n})\nkeymap('n', '<Leader>crr', '<Plug>(yarepl-send-line-aichat)', {\n    desc = 'Send lines to Aichat',\n})\nkeymap('n', '<Leader>cr', '<Plug>(yarepl-send-operator-aichat)', {\n    desc = 'Send Operator to Aichat',\n})\nkeymap('n', '<Leader>cr', '<Plug>(yarepl-source-operator-aichat)', {\n    desc = 'Source Operator to Aichat',\n})\nkeymap('n', '<Leader>ce', '<Plug>(yarepl-exec-aichat)', {\n    desc = 'Execute command in aichat',\n})\nkeymap('n', '<Leader>cq', '<Plug>(yarepl-close-aichat)', {\n    desc = 'Quit Aichat',\n})\n\n\nlocal ft_to_repl = {\n    r = 'radian',\n    R = 'radian',\n    rmd = 'radian',\n    quarto = 'radian',\n    markdown = 'radian',\n    python = 'ipython',\n    sh = 'bash',\n}\n\nautocmd('FileType', {\n    pattern = { 'quarto', 'markdown', 'markdown.pandoc', 'rmd', 'python', 'sh', 'REPL', 'r' },\n    group = my_augroup,\n    desc = 'set up REPL keymap',\n    callback = function()\n        local repl = ft_to_repl[vim.bo.filetype]\n        repl = repl and ('-' .. repl) or ''\n\n        bufmap(0, 'n', '<LocalLeader>rs', string.format('<Plug>(yarepl-start%s)', repl), {\n            desc = 'Start an REPL',\n        })\n        bufmap(0, 'n', '<LocalLeader>rf', '<Plug>(yarepl-focus)', {\n            desc = 'Focus on REPL',\n        })\n        bufmap(0, 'n', '<LocalLeader>rv', '<CMD>Telescope yarepl_show<CR>', {\n            desc = 'View REPLs in telescope',\n        })\n        bufmap(0, 'n', '<LocalLeader>rh', '<Plug>(yarepl-hide)', {\n            desc = 'Hide REPL',\n        })\n        bufmap(0, 'v', '<LocalLeader>s', '<Plug>(yarepl-send-visual)', {\n            desc = 'Send visual region to REPL',\n        })\n        bufmap(0, 'v', '<LocalLeader>S', '<Plug>(yarepl-source-visual)', {\n            desc = 'Source visual region to REPL',\n        })\n        bufmap(0, 'n', '<LocalLeader>ss', '<Plug>(yarepl-send-line)', {\n            desc = 'Send line to REPL',\n        })\n        bufmap(0, 'n', '<LocalLeader>s', '<Plug>(yarepl-send-operator)', {\n            desc = 'Send operator to REPL',\n        })\n        bufmap(0, 'n', '<LocalLeader>S', '<Plug>(yarepl-source-operator)', {\n            desc = 'Source operator to REPL',\n        })\n        bufmap(0, 'n', '<LocalLeader>re', '<Plug>(yarepl-exec)', {\n            desc = 'Execute command in REPL',\n            expr = true,\n        })\n        bufmap(0, 'n', '<LocalLeader>rq', '<Plug>(yarepl-close)', {\n            desc = 'Quit REPL',\n        })\n        bufmap(0, 'n', '<LocalLeader>rc', '<CMD>Yarepl cleanup<CR>', {\n            desc = 'Clear REPLs.',\n        })\n        bufmap(0, 'n', '<LocalLeader>rS', '<CMD>Yarepl swap<CR>', {\n            desc = 'Swap REPLs.',\n        })\n        bufmap(0, 'n', '<LocalLeader>r?', '<Plug>(yarepl-start)', {\n            desc = 'Start an REPL from available REPL metas',\n        })\n        bufmap(0, 'n', '<LocalLeader>ra', '<CMD>Yarepl attach_buffer<CR>', {\n            desc = 'Attach current buffer to a REPL',\n        })\n        bufmap(0, 'n', '<LocalLeader>rd', '<CMD>Yarepl detach_buffer<CR>', {\n            desc = 'Detach current buffer to any REPL',\n        })\n    end,\n})\n\n```\n\nWith the keybinding setup, prefixing keybindings with <Leader>c ensures that\nthe text is always sent to the aichat REPL, a REPL for chatgpt.\n\nFor maximum flexibility with other programming languages, the maintainer\ndesires the ability to easily switch between two modes:\n\n1. Sending text from multiple files to a REPL via `2<LocalLeader>s`, regardless\n   of which buffer the maintainer is visiting. This guarantees that the text is\n   always sent to `RPEL 2`.\n\n2. Sending text to a dedicated REPL for each buffer. To avoid the hassle of\n   remembering the exact ID associated with the desired REPL, the maintainer\n   can use `<LocalLeader>ra` to attach the current buffer to a REPL.\n   Subsequently, the `<LocalLeader>s` key can be directly used to send the text\n   to the desired REPL.\n\n# Extensions\n\nThe `Extensions` module contains extended functionalities built upon the core\nof yarepl.nvim. While not considered as core part of yarepl, it offers valuable\nadditional features. For comprehensive information about the features, please\nrefer to [extensions/README.md](extensions/README.md).\n\nCurrently, the module includes:\n\n## aider\n\nThis module enhances AI-assisted coding capabilities through\n[aider.chat](https://aider.chat) integration.\n\n## codex\n\nThis module enhances AI-assisted coding capabilities through [OpenAI's Codex\nCLI](https://github.com/openai/codex) integration.\n\n## opencode\n\nThis module enhances AI-assisted coding capabilities through\n[OpenCode](https://opencode.ai) integration. Its extension-specific `<Plug>`\nmaps follow the same lowercase naming pattern, for example\n`<Plug>(yarepl-opencode-exec)`.\n\n## code-cell\n\nThis module simplifies the creation of code cell text objects, allowing you to\nutilize them with `Yarepl send_operator` or other operators such as paste, delete,\nand formatting.\n\n## fzf-lua\n\nThis module provides a fuzzy finder interface to preview active REPLs with `fzf-lua`.\n\n## telescope\n\nThis module provides a fuzzy finder interface to preview active REPLs with `telescope`.\n\n## Snacks.picker\n\nThis module provides a fuzzy finder interface to preview active REPLs with `Snacks.picker`.\n\n# Set up project-level REPLs\n\nYou may want to have the ability to control the REPL metas at the project\nlevel. For example, you may want to open `ipython` installed in a conda\nenvironment for one project and a different `ipython` installed in another\nconda environment for another project.\n\nOne way to achieve this is to:\n\n- Enable the built-in `exrc`, which requires `nvim 0.9` for security reasons.\n\nTo enable `exrc`, add the following line to your Neovim config:\n\n```lua\nvim.o.exrc = true\n```\n\nThen, configure `yarepl` like so:\n\n```lua\nvim.g.yarepl_ipython_paths = vim.g.yarepl_ipython_paths or {}\nlocal yarepl = require 'yarepl'\n\nrequire('yarepl').setup {\n    metas = {\n        ipython = {\n            cmd = function()\n                local cwd = vim.fn.getcwd()\n                if vim.g.yarepl_ipython_paths and vim.g.yarepl_ipython_paths[cwd] then\n                    return vim.g.yarepl_ipython_paths[cwd]\n                else\n                    return 'ipython'\n                end\n            end,\n        },\n    },\n}\n```\n\nNow, in the project root directory `~/projects/project1`, create a file\ncalled `.nvim.lua` with the following lines:\n\n```lua\nlocal cwd = vim.fn.getcwd()\n\nif vim.g.yarepl_ipython_paths then\n    vim.g.yarepl_ipython_paths[cwd] = '~/mambaforge/envs/a-conda-env/bin/ipython'\nelse\n    vim.g.yarepl_ipython_paths = {\n        [cwd] = '~/mambaforge/envs/a-conda-env/bin/ipython',\n    }\nend\n```\n\nThe first time you open `project1`, Neovim will prompt you to decide whether\nyou want to load the `.nvim.lua` file. Please allow it.\n\n**Note:** The `.nvim.lua` file will be automatically loaded only once when\nNeovim starts. Thus, if you switch working directories during the time Neovim\nis running, the `.nvim.lua` file won't be loaded at the new working directory.\nTo manually load the `.nvim.lua` file after switching to a new working\ndirectory, try `:luafile .nvim.lua`.\n\n# Create persistent REPLs in tmux\n\nIf you would like to maintain a persistent REPL process even after exiting\nneovim, you can utilize tmux. To achieve this, the following configuration\ncreates a REPL meta named `ipy_tmux` that attaches to a tmux session named\n`ipython`. If the session does not exist, a new tmux session named `ipython` is\ncreated, and an `ipython` REPL is started.\n\n```lua\nmetas = {\n    ipy_tmux = {\n        cmd = 'tmux attach -t ipython || tmux new -s ipython ipython',\n        formatter = yarepl.formatter.bracketed_pasting,\n    },\n}\n```\n\n# FAQ\n\n## Why lazy loading with `lazy.nvim` doesn't work?\n\nWe recommend using `event = 'VeryLazy'` to do the lazy loading. If you want to\nuse `keys` to lazy load this plugin, make sure you are using recursive mapping:\n\n```lua\n-- Recommended\nreturn {\n    'milanglacier/yarepl.nvim',\n    event = 'VeryLazy',\n    config = function()\n        -- add your configs here\n    end,\n}\n\n-- Also works, but use with caution!\nreturn {\n    'milanglacier/yarepl.nvim',\n    keys = {\n        { '<Leader>s', '<Plug>(yarepl-start)', noremap = false, mode = 'n' },\n        { '<LocalLeader>o', '<Plug>(yarepl-start-ipython)', noremap = false, ft = 'python', mode = 'n' },\n    },\n    config = function()\n        -- your config here\n    end,\n}\n```\n\n## How do I avoid clutter from the bufferline plugin?\n\nIf you are using a bufferline plugin and do not want the REPL buffers to\nclutter your bufferline, pass `buflisted = false` in the `setup` function.\n\nIn case you have unlisted the REPLs and need to view the running ones, use\n`Telescope yarepl_show`.\n\n## Yarepl send_visual is not functioning properly\n\nRefer to [Yarepl send_visual](#yarepl-send_visual)\n\n## `<Plug>(yarepl-send-visual)` Only Sends to First REPL\n\nWhen using which-key.nvim and binding `<Plug>(yarepl-send-visual)` or its variants\n(like `<Plug>(yarepl-send-visual-ipython)`) to keybindings that start with leader\nor local leader keys, visual selections will always be sent to the first REPL,\nregardless of any numeric prefix entered.\n\nThis behavior occurs due to a conflict with which-key.nvim, as it consumes the\ncount input before it reaches `<Plug>(yarepl-send-visual)`, resulting in a count\nvalue of `0`.\n\nTo resolve this issue, you have several options:\n\n1. Disable which-key.nvim in visual mode\n2. Bind `<Plug>(yarepl-send-visual)` to key sequences that don't trigger which-key\n   (e.g., `<A-s>`)\n3. Use alternative methods such as `Yarepl attach_buffer` to connect the\n   current buffer to a REPL other than the first one\n\n# Limitations\n\n- Currently, `yarepl` does not support sending block-wise visual selections. If\n  a user attempts to send code while in block-wise visual mode, it will\n  automatically fall back to sending the selection line-wise.\n\n# Acknowledgements\n\n- [iron.nvim](https://github.com/Vigemus/iron.nvim)\n- [toggleterm.nvim](https://github.com/akinsho/toggleterm.nvim)\n"
  },
  {
    "path": "extensions/README.md",
    "content": "- [Aider](#aider)\n  - [Overview](#overview)\n  - [Features](#features)\n  - [Commands](#commands)\n  - [Keymaps](#keymaps)\n  - [Usage](#usage)\n    - [Example keybinding Setup](#example-keybinding-setup)\n  - [Customization](#customization)\n  - [Note](#note)\n- [Codex](#codex)\n  - [Overview](#overview-1)\n  - [Features](#features-1)\n  - [Commands](#commands-1)\n  - [Keymaps](#keymaps-1)\n  - [Usage](#usage-1)\n    - [Example keybinding Setup](#example-keybinding-setup-1)\n  - [Customization](#customization-1)\n- [OpenCode](#opencode)\n  - [Overview](#overview-2)\n  - [Features](#features-2)\n  - [Commands](#commands-2)\n  - [Keymaps](#keymaps-2)\n  - [Usage](#usage-2)\n    - [Example keybinding Setup](#example-keybinding-setup-2)\n  - [Customization](#customization-2)\n- [Code Cell](#code-cell)\n  - [Overview](#overview-3)\n  - [Features](#features-3)\n  - [Usage](#usage-3)\n    - [Example Configuration](#example-configuration)\n- [Telescope Integration](#telescope-integration)\n- [Fzf-lua Integration](#fzf-lua-integration)\n- [Snacks.picker Integration](#snackspicker-integration)\n\n**Breaking change:** extension `<Plug>` mappings now use lowercase `yarepl`\nnames. Update old forms like `<Plug>(Yarepl-aider-send-visual)`, to\n`<Plug>(yarepl-aider-send-visual)`,\n\nAider, Codex, and OpenCode also live under the unified `Yarepl` command tree.\nThe old top-level commands are being replaced by forms like `:Yarepl aider\nexec`, `:Yarepl aider set_prefix /ask`, `:Yarepl codex send_status`, `:Yarepl\ncodex send_open_editor`, and `:Yarepl opencode send_models`.\n\nIf you were used to `AiderExec`, `AiderSetPrefix`, `CodexExec`, or\n`<Plug>(AiderSendYes)`, the new names are the same actions with a more regular\nshape: snake-style subcommands on the command line, kebab-style names inside\n`<Plug>(...)`.\n\nThe legacy commands and keymaps (`REPL*`) still function for now, but they will\nbe removed on `2026-06-01`.\n\nThis keeps the extension side predictable. You get one command namespace, the\nsame completion behavior everywhere, and a single place to add new actions\ninstead of another standalone command for each one.\n\n# Aider\n\n## Overview\n\nThis is an auxiliary functionality for\nyarepl designed to enhance\nthe integration with the [aider](https://github.com/paul-gauthier/aider) AI\ncoding assistant. It provides a set of commands and keymaps to streamline the\ninteraction between Neovim and aider, making it easier to use AI-assisted\ncoding within your editor.\n\n## Features\n\n- Seamless integration with yarepl.nvim for aider sessions\n- Custom prefix handling for aider commands\n- Predefined shortcuts for common aider actions\n- Configurable aider arguments\n\n## Commands\n\nThe `yarepl.extensions.aider` module offers command-line completions for the\nunified Aider subcommands.\n\n- `Yarepl aider set_prefix`: Specify a `/` prefix for Aider commands, such as\n  `/ask`, `/architect`, `/context`, etc. When sending buffer content to the\n  Aider REPL, the specified prefix will be prepended to the buffer content.\n- `Yarepl aider remove_prefix`: Remove the current prefix.\n- `Yarepl aider send_yes`: Send `y` to aider.\n- `Yarepl aider send_no`: Send `n` to aider.\n- `Yarepl aider send_abort`: Send abort signal (`C-c`) to aider.\n- `Yarepl aider send_exit`: Send exit signal (`C-d`) to aider.\n- `Yarepl aider send_diff`: Send `/diff` to aider.\n- `Yarepl aider send_paste`: Send `/paste` to aider, particularly useful for\n  sending images.\n- `Yarepl aider send_clear`: Send `/clear` to aider.\n- `Yarepl aider send_undo`: Send `/undo` to aider.\n- `Yarepl aider send_reset`: Send `/reset` to aider.\n- `Yarepl aider send_drop`: Send `/drop` to aider.\n- `Yarepl aider send_ls`: Send `/ls` to aider.\n- `Yarepl aider send_ask_mode`: Switch aider to _ask_ mode.\n- `Yarepl aider send_arch_mode`: Switch aider to _architect_ mode.\n- `Yarepl aider send_code_mode`: Switch aider to _code_ mode.\n- `Yarepl aider send_context_mode`: Switch aider to _context_ mode.\n\n  **Note**: `send_context_mode` requires `aider v0.79.0+`\n\n- `Yarepl aider exec`: Send the prompt written in cmdline to aider with `/`\n  prefix completion.\n- `Yarepl aider set_args`: Set the command line args to launch aider with\n  autocompletion, for example `Yarepl aider set_args --model gpt-4o`.\n\n## Keymaps\n\nIn addition to the general `<Plug>` maps created by yarepl.nvim, aider.lua\nprovides a set of additional `<Plug>` mappings to enhance the experience with\naider:\n\n- `<Plug>(yarepl-aider-send-line)`: Send current line to aider.\n- `<Plug>(yarepl-aider-send-visual)`: Send visual selection to aider.\n- `<Plug>(yarepl-aider-send-operator)`: Operator to send text to aider.\n- `<Plug>(yarepl-aider-exec)`: Type the prompt in cmdline and send it to aider.\n- `<Plug>(yarepl-aider-send-yes)`: Send `y` to aider.\n- `<Plug>(yarepl-aider-send-no)`: Send `n` to aider.\n- `<Plug>(yarepl-aider-send-abort)`: Send abort signal (`C-c`) to aider.\n- `<Plug>(yarepl-aider-send-exit)`: Send exit signal (`C-d`) to aider.\n- `<Plug>(yarepl-aider-send-diff)`\n- `<Plug>(yarepl-aider-send-paste)`: Send `/paste`, particularly useful for\n  sending images.\n- `<Plug>(yarepl-aider-send-clear)`\n- `<Plug>(yarepl-aider-send-undo)`\n- `<Plug>(yarepl-aider-send-reset)`\n- `<Plug>(yarepl-aider-send-drop)`\n- `<Plug>(yarepl-aider-send-ls)`\n- `<Plug>(yarepl-aider-send-ask-mode)`: Switch aider to _ask_ mode.\n- `<Plug>(yarepl-aider-send-arch-mode)`: Switch aider to _architect_ mode.\n- `<Plug>(yarepl-aider-send-code-mode)`: Switch aider to _code_ mode.\n- `<Plug>(yarepl-aider-send-context-mode)`: Switch aider to _context_ mode.\n\n## Usage\n\nMake sure you have added aider into your repl meta:\n\n```lua\nrequire('yarepl').setup {\n    metas = { aider = require('yarepl.extensions.aider').create_aider_meta() }\n}\n```\n\n### Example keybinding Setup\n\nHere's an example of how you can set up your keybindings in your Neovim\nconfiguration:\n\nIn this example, `<Leader>a` is used as the prefix for aider-related\nkeybindings. You can customize these to your preference.\n\nFor more detailed information on using aider, refer to the [aider\ndocumentation](https://aider.chat/).\n\n```lua\nlocal keymap = vim.api.nvim_set_keymap\n\n-- general keymap from yarepl\nkeymap('n', '<Leader>cs', '<Plug>(yarepl-start-aider)', { desc = 'Start aider' })\nkeymap('n', '<Leader>cf', '<Plug>(yarepl-focus-aider)', { desc = 'Focus aider' })\nkeymap('n', '<Leader>ch', '<Plug>(yarepl-hide-aider)', { desc = 'Hide aider' })\nkeymap('v', '<Leader>cr', '<Plug>(yarepl-send-visual-aider)', { desc = 'Send visual to aider' })\nkeymap('n', '<Leader>crr', '<Plug>(yarepl-send-line-aider)', { desc = 'Send line to aider' })\nkeymap('n', '<Leader>cr', '<Plug>(yarepl-send-operator-aider)', { desc = 'Send operator to aider' })\n\n-- special keymap from aider\nkeymap('n', '<Leader>ae', '<Plug>(yarepl-aider-exec)', {\n    desc = 'Execute command in aider',\n})\nkeymap('n', '<Leader>ay', '<Plug>(yarepl-aider-send-yes)', {\n    desc = 'Send y to aider',\n})\nkeymap('n', '<Leader>an', '<Plug>(yarepl-aider-send-no)', {\n    desc = 'Send n to aider',\n})\nkeymap('n', '<Leader>ap', '<Plug>(yarepl-aider-send-paste)', {\n    desc = 'Send /paste to aider',\n})\nkeymap('n', '<Leader>aa', '<Plug>(yarepl-aider-send-abort)', {\n    desc = 'Send abort to aider',\n})\nkeymap('n', '<Leader>aq', '<Plug>(yarepl-aider-send-exit)', {\n    desc = 'Send exit to aider',\n})\nkeymap('n', '<Leader>ag', '<cmd>Yarepl aider set_prefix<cr>', {\n    desc = 'set aider prefix',\n})\nkeymap('n', '<Leader>ama', '<Plug>(yarepl-aider-send-ask-mode)', {\n    desc = 'Switch aider to ask mode',\n})\nkeymap('n', '<Leader>amA', '<Plug>(yarepl-aider-send-arch-mode)', {\n    desc = 'Switch aider to architect mode',\n})\nkeymap('n', '<Leader>amc', '<Plug>(yarepl-aider-send-code-mode)', {\n    desc = 'Switch aider to code mode',\n})\nkeymap('n', '<Leader>aG', '<cmd>Yarepl aider remove_prefix<cr>', {\n    desc = 'remove aider prefix',\n})\nkeymap('n', '<Leader>a<space>', '<cmd>checktime<cr>', {\n    desc = 'sync file changes by aider to nvim buffer',\n})\n```\n\n## Customization\n\n`yarepl.extensions.aider` comes with the following default:\n\n```lua\nrequire('yarepl.extensions.aider').setup {\n    aider_cmd = 'aider',\n    --NOTE: make sure you pass a list of string, not string,\n    aider_args = { '--watch-files' },\n    -- Display a winbar (e.g., \"aider#<id>\") in the floating window.\n    show_winbar_in_float_win = true,\n    -- The default wincmd is to open aider in a floating window at the bottom-right corner\n    wincmd = require('yarepl.extensions.aider').config.wincmd,\n}\n```\n\n## Note\n\nI recommend explore the `inline comment as instruction` feature in `aider`,\nwhich is enabled by default for this extension. See the\n[documentation](https://aider.chat/docs/usage/watch.html).\n\n# Codex\n\n## Overview\n\nThis extension integrates the Codex CLI with yarepl to provide a smooth\nworkflow inside Neovim. It offers commands, keymaps, and a ready-to-use meta to\nlaunch and interact with Codex.\n\n## Features\n\n- Seamless yarepl integration for Codex sessions\n- Completions for common slash-style Codex commands\n- Predefined shortcuts for frequent actions (Abort, Exit, Diff, Status, etc.)\n- Configurable Codex command and arguments\n- Floating window default for a focused REPL experience\n\n## Commands\n\n- `Yarepl codex set_args`: Set CLI arguments for launching Codex with\n  completion support, for example `Yarepl codex set_args --model gpt-5`.\n- `Yarepl codex send_abort`: Send Ctrl-C to Codex.\n- `Yarepl codex send_exit`: Send Ctrl-D to Codex.\n- `Yarepl codex send_diff`: Send `/diff` to Codex.\n- `Yarepl codex send_status`: Send `/status` to Codex.\n- `Yarepl codex send_model`: Send `/model` to Codex.\n- `Yarepl codex send_new`: Send `/new` to Codex.\n- `Yarepl codex send_approvals`: Send `/approvals` to Codex.\n- `Yarepl codex send_compact`: Send `/compact` to Codex.\n- `Yarepl codex send_open_editor`: Ask Codex to open the editor (`Ctrl-G`).\n- `Yarepl codex send_transcript_enter`: Send `Ctrl-T`.\n- `Yarepl codex send_transcript_quit`: Send `q`.\n- `Yarepl codex send_transcript_begin`: Send `Home`.\n- `Yarepl codex send_transcript_end`: Send `End`.\n- `Yarepl codex send_page_up`: Send `PageUp`.\n- `Yarepl codex send_page_down`: Send `PageDown`.\n- `Yarepl codex exec`: Type a prompt or slash command in the cmdline and send\n  it to Codex, with completion for common prefixes like `/model`,\n  `/approvals`, `/init`, `/new`, `/compact`, `/diff`, `/mention`, `/status`.\n\nAll commands accept an optional count to target a specific Codex REPL id.\n\n## Keymaps\n\nIn addition to the general `<Plug>` maps created by yarepl once the `codex`\nmeta is registered (e.g. `<Plug>(yarepl-codex-send-line)`), this extension\ndefines extra convenience maps:\n\n- `<Plug>(yarepl-codex-exec)`: Type in cmdline and send to Codex.\n- `<Plug>(yarepl-codex-send-abort)`: Send Ctrl-C.\n- `<Plug>(yarepl-codex-send-exit)`: Send Ctrl-D.\n- `<Plug>(yarepl-codex-send-diff)`\n- `<Plug>(yarepl-codex-send-status)`\n- `<Plug>(yarepl-codex-send-model)`\n- `<Plug>(yarepl-codex-send-new)`\n- `<Plug>(yarepl-codex-send-approvals)`\n- `<Plug>(yarepl-codex-send-compact)`\n- `<Plug>(yarepl-codex-send-open-editor)`: Ask Codex to open the editor\n  (`Ctrl-G`).\n- `<Plug>(yarepl-codex-send-transcript-enter)`\n- `<Plug>(yarepl-codex-send-transcript-quit)`\n- `<Plug>(yarepl-codex-send-transcript-begin)`: Send `<Home>`.\n- `<Plug>(yarepl-codex-send-transcript-end)`: Send `<End>`.\n- `<Plug>(yarepl-codex-send-page-up)`\n- `<Plug>(yarepl-codex-send-page-down)`\n\nYou can prefix a count (e.g. `2`) before a mapping to target that REPL id.\n\n## Usage\n\nAdd the Codex meta to your setup:\n\n```lua\nrequire('yarepl').setup {\n  metas = {\n    codex = require('yarepl.extensions.codex').create_codex_meta(),\n  },\n}\n```\n\nFor the best experience using the `Open Editor` (Ctrl‑G) command with Codex,\ninstall the [neovim-remote](https://github.com/mhinz/neovim-remote) plugin\n(until Neovim provides an official `--remote-wait`) and set your `EDITOR`\ninside Neovim to an `nvr` command. For example:\n\n```lua\nvim.env.EDITOR = 'nvr -cc tabnew --remote-wait'\n```\n\nTo return from an nvr instance to Codex, use `:w | bdelete` instead of `:wq`,\nas nvr only exits when the buffer is deleted, allowing Codex to receive the\nupdated content. You can also define a convenient `WQ` command with this\nVimscript one-liner:\n\n```vim\ncommand! WQ w | bdelete\n```\n\n### Example keybinding Setup\n\n```lua\nlocal keymap = vim.api.nvim_set_keymap\n\n-- general yarepl keymaps for the codex meta\nkeymap('n', '<Leader>cs', '<Plug>(yarepl-start-codex)', { desc = 'Start codex' })\nkeymap('n', '<Leader>cf', '<Plug>(yarepl-focus-codex)', { desc = 'Focus codex' })\nkeymap('n', '<Leader>ch', '<Plug>(yarepl-hide-codex)', { desc = 'Hide codex' })\nkeymap('v', '<Leader>cr', '<Plug>(yarepl-send-visual-codex)', { desc = 'Send visual to codex' })\nkeymap('n', '<Leader>crr', '<Plug>(yarepl-send-line-codex)', { desc = 'Send line to codex' })\nkeymap('n', '<Leader>cr', '<Plug>(yarepl-send-operator-codex)', { desc = 'Send operator to codex' })\n\n-- codex-specific convenience keymaps\nkeymap('n', '<Leader>ce', '<Plug>(yarepl-codex-exec)', { desc = 'Exec in Codex' })\nkeymap('n', '<Leader>ca', '<Plug>(yarepl-codex-send-abort)', { desc = 'Abort' })\nkeymap('n', '<Leader>cD', '<Plug>(yarepl-codex-send-exit)', { desc = 'Exit' })\nkeymap('n', '<Leader>cd', '<Plug>(yarepl-codex-send-diff)', { desc = 'Diff' })\nkeymap('n', '<Leader>ct', '<Plug>(yarepl-codex-send-status)', { desc = 'Status' })\nkeymap('n', '<Leader>cm', '<Plug>(yarepl-codex-send-model)', { desc = 'Model' })\nkeymap('n', '<Leader>cn', '<Plug>(yarepl-codex-send-new)', { desc = 'New' })\nkeymap('n', '<Leader>cA', '<Plug>(yarepl-codex-send-approvals)', { desc = 'Approvals' })\nkeymap('n', '<Leader>cc', '<Plug>(yarepl-codex-send-compact)', { desc = 'Compact' })\nkeymap('n', '<Leader>co', '<Plug>(yarepl-codex-send-open-editor)', { desc = 'Open editor' })\n-- transcript and navigation helpers\nkeymap('n', '<Leader>cte', '<Plug>(yarepl-codex-send-transcript-enter)', { desc = 'Transcript mode' })\nkeymap('n', '<Leader>ctq', '<Plug>(yarepl-codex-send-transcript-quit)', { desc = 'Transcript quit' })\nkeymap('n', '<Leader>ctg', '<Plug>(yarepl-codex-send-transcript-begin)', { desc = 'Transcript begin' })\nkeymap('n', '<Leader>ctG', '<Plug>(yarepl-codex-send-transcript-end)', { desc = 'Transcript end' })\nkeymap('n', '<Leader>ctk', '<Plug>(yarepl-codex-send-page-up)', { desc = 'Transcript page up' })\nkeymap('n', '<Leader>ctj', '<Plug>(yarepl-codex-send-page-down)', { desc = 'Transcript page down' })\nkeymap('n', '<Leader>c<space>', '<cmd>checktime<cr>', {\n    desc = 'sync file changes by codex to nvim buffer',\n})\n```\n\n## Customization\n\nDefault configuration:\n\n```lua\nrequire('yarepl.extensions.codex').setup {\n      codex_cmd = 'codex',\n      codex_args = {},\n      -- Warn when $EDITOR is unset or not using nvr (for OpenEditor).\n      warn_on_EDITOR_env_var = true,\n      -- Display a winbar (e.g., \"codex#<id>\") in the floating window.\n      show_winbar_in_float_win = true,\n      -- The default is a floating window at the bottom right corner; you can override it\n      wincmd = require('yarepl.extensions.codex').config.wincmd,\n}\n```\n\n# OpenCode\n\n## Overview\n\nThis extension integrates the OpenCode with yarepl. It provides a ready to use\nREPL meta, completions for common slash commands, and convenience commands for\nthe most used TUI keybinds.\n\n## Features\n\n- Seamless yarepl integration for OpenCode sessions\n- Completions for common OpenCode slash commands\n- Convenience shortcuts for OpenCode's `ctrl+x` leader commands\n- Configurable OpenCode command and arguments\n- Floating window default for a focused REPL experience\n\n## Commands\n\n- `Yarepl opencode set_args`: Set CLI arguments for launching OpenCode with\n  completion support, for example `Yarepl opencode set_args --model xxx`\n- `Yarepl opencode send_compact`: Send `/compact` to OpenCode.\n- `Yarepl opencode send_connect`: Send `/connect` to OpenCode.\n- `Yarepl opencode send_open_editor`: Send `ctrl+x e` to OpenCode.\n- `Yarepl opencode send_exit`: Send `/exit` to OpenCode.\n- `Yarepl opencode send_export`: Send `/export` to OpenCode.\n- `Yarepl opencode send_help`: Send `/help` to OpenCode.\n- `Yarepl opencode send_init`: Send `/init` to OpenCode.\n- `Yarepl opencode send_models`: Send `/models` to OpenCode.\n- `Yarepl opencode send_new`: Send `/new` to OpenCode.\n- `Yarepl opencode send_redo`: Send `/redo` to OpenCode.\n- `Yarepl opencode send_sessions`: Send `/sessions` to OpenCode.\n- `Yarepl opencode send_share`: Send `/share` to OpenCode.\n- `Yarepl opencode send_thinking`: Send `/thinking` to OpenCode.\n- `Yarepl opencode send_undo`: Send `/undo` to OpenCode.\n- `Yarepl opencode send_unshare`: Send `/unshare` to OpenCode.\n- `Yarepl opencode send_scroll_up`: Send `ctrl+alt+u` to OpenCode.\n- `Yarepl opencode send_scroll_down`: Send `ctrl+alt+d` to OpenCode.\n- `Yarepl opencode exec`: Send the prompt written in cmdline to OpenCode, with\n  completion for common prefixes like `/compact`, `/connect`, `/editor`,\n  `/models`, `/sessions`, `/thinking`, and `/undo`.\n\nAll commands accept an optional count to target a specific OpenCode REPL id.\n\n## Keymaps\n\nIn addition to the general `<Plug>` maps created by yarepl once the `opencode`\nmeta is registered, this extension defines extra convenience maps:\n\n- `<Plug>(yarepl-opencode-exec)`: Type in cmdline and send to OpenCode.\n- `<Plug>(yarepl-opencode-send-compact)`\n- `<Plug>(yarepl-opencode-send-connect)`\n- `<Plug>(yarepl-opencode-send-open-editor)`: Send `ctrl+x e`.\n- `<Plug>(yarepl-opencode-send-exit)`\n- `<Plug>(yarepl-opencode-send-export)`\n- `<Plug>(yarepl-opencode-send-help)`\n- `<Plug>(yarepl-opencode-send-init)`\n- `<Plug>(yarepl-opencode-send-models)`\n- `<Plug>(yarepl-opencode-send-new)`\n- `<Plug>(yarepl-opencode-send-redo)`\n- `<Plug>(yarepl-opencode-send-sessions)`\n- `<Plug>(yarepl-opencode-send-share)`\n- `<Plug>(yarepl-opencode-send-thinking)`\n- `<Plug>(yarepl-opencode-send-undo)`\n- `<Plug>(yarepl-opencode-send-unshare)`\n- `<Plug>(yarepl-opencode-send-scroll-up)`: Send `ctrl+alt+u`.\n- `<Plug>(yarepl-opencode-send-scroll-down)`: Send `ctrl+alt+d`.\n\nYou can prefix a count (e.g. `2`) before a mapping to target that REPL id.\n\n## Usage\n\nAdd the OpenCode meta to your setup:\n\n```lua\nrequire('yarepl').setup {\n  metas = {\n    opencode = require('yarepl.extensions.opencode').create_opencode_meta(),\n  },\n}\n```\n\n### Example keybinding Setup\n\n```lua\nlocal keymap = vim.api.nvim_set_keymap\n\n-- general yarepl keymaps for the opencode meta\nkeymap('n', '<Leader>os', '<Plug>(yarepl-start-opencode)', { desc = 'Start OpenCode' })\nkeymap('n', '<Leader>of', '<Plug>(yarepl-focus-opencode)', { desc = 'Focus OpenCode' })\nkeymap('n', '<Leader>oh', '<Plug>(yarepl-hide-opencode)', { desc = 'Hide OpenCode' })\nkeymap('v', '<Leader>or', '<Plug>(yarepl-send-visual-opencode)', { desc = 'Send visual to OpenCode' })\nkeymap('n', '<Leader>orr', '<Plug>(yarepl-send-line-opencode)', { desc = 'Send line to OpenCode' })\nkeymap('n', '<Leader>or', '<Plug>(yarepl-send-operator-opencode)', { desc = 'Send operator to OpenCode' })\n\n-- opencode-specific convenience keymaps\nkeymap('n', '<Leader>oe', '<Plug>(yarepl-opencode-exec)', { desc = 'Exec in OpenCode' })\nkeymap('n', '<Leader>oo', '<Plug>(yarepl-opencode-send-open-editor)', { desc = 'Open editor' })\nkeymap('n', '<Leader>ou', '<Plug>(yarepl-opencode-send-scroll-up)', { desc = 'Scroll up' })\nkeymap('n', '<Leader>od', '<Plug>(yarepl-opencode-send-scroll-down)', { desc = 'Scroll down' })\n```\n\n## Customization\n\nDefault configuration:\n\n```lua\nrequire('yarepl.extensions.opencode').setup {\n      opencode_cmd = 'opencode',\n      opencode_args = {},\n      -- Display a winbar (e.g., \"opencode#<id>\") in the floating window.\n      show_winbar_in_float_window = true,\n      -- The default is a floating window at the bottom right corner; you can override it\n      wincmd = require('yarepl.extensions.opencode').config.wincmd,\n}\n```\n\n# Code Cell\n\n## Overview\n\nThe code cell extension provides text objects for working with code cells in various file types. Code cells are sections of code delimited by specific patterns, commonly used in literate programming and notebook-style documents.\n\n## Features\n\n- Text objects for selecting code cells\n- Support for both \"inner\" and \"around\" selections\n- Configurable patterns for different file types\n- Automatic setup based on file type\n\n## Usage\n\nThe extension creates text objects for code cell selection using defined start\nand end patterns.\n\n### Example Configuration\n\nThe module requires explicit configuration to activate, as it has no default\nsettings. Below is a sample configuration that enables:\n\n- Markdown-style code blocks (triple backticks) in rmd, quarto, and markdown files\n- Python/R-style code cells (`# %%`) in python and R files\n\n````lua\nrequire('yarepl.extensions.code_cell').register_text_objects {\n    {\n        key = 'c',\n        start_pattern = '```.+',\n        end_pattern = '^```$',\n        ft = { 'rmd', 'quarto', 'markdown' },\n        desc = 'markdown code cells',\n    },\n    {\n        key = '<Leader>c',\n        start_pattern = '^# ?%%%%.*',\n        end_pattern = '^# ?%%%%.*',\n        ft = { 'r', 'python' },\n        desc = 'r/python code cells',\n    },\n}\n````\n\n**Usage Examples**:\n\nMarkdown files (using key `c`):\n\n- `ic`: Select cell content (excludes delimiters)\n- `ac`: Select entire cell (includes delimiters)\n\nPython/R files (using `<Leader>c`):\n\n- `i<Leader>c`: Select content between `# %%` markers\n- `a<Leader>c`: Select content including `# %%` markers\n\nNote: Use Lua patterns rather than Vim regex patterns.\n\nThese text objects function in both operator-pending and visual modes.\n\nTo send code cells to REPL, map `<Plug>(yarepl-send-operator)` to `<Leader>s`, then\nuse `<Leader>sic` to send the current cell.\n\n# Telescope Integration\n\n`yarepl` has integrated with Telescope and can be enabled by adding the\nfollowing line to your config:\n\n```lua\nrequire('telescope').load_extension 'yarepl_show'\n```\n\nOnce added, you can use `Telescope yarepl_show` to preview the active REPL\nbuffers. This integration allows you to preview active REPL buffers. Pressing\n`<CR>` will open the selected REPL buffer using `wincmd`, either with a\nmeta-local `wincmd` or the global `wincmd`, depending on the context.\n\n# Fzf-lua Integration\n\n`yarepl` has integrated with `Fzf-lua` and can be enabled by adding the\nfollowing line to your config:\n\n```lua\nvim.keymap.set('n', '<Leader>rv', function() require('yarepl.extensions.fzf').repl_show() end)\n```\n\nThis integration allows you to preview active REPL buffers. Pressing `<CR>`\nwill open the selected REPL buffer using `wincmd`, either with a meta-local\n`wincmd` or the global `wincmd`, depending on the context.\n\nFor users familiar with `Fzf-lua`'s API, custom options can be passed to the\nfunction to tailor its behavior, similar to any other `Fzf-lua` pickers. For\nexample:\n\n```lua\nrequire('yarepl.extensions.fzf').repl_show {\n    winopts = {\n        title = 'REPL>',\n        previewer = {\n            layout = 'horizontal'\n        }\n    }\n}\n```\n\n# Snacks.picker Integration\n\n`yarepl` has integrated with `Snacks.picker` and can be enabled by adding the\nfollowing line to your config:\n\n```lua\nvim.keymap.set('n', '<Leader>rv', function() require('yarepl.extensions.snacks').repl_show() end)\n```\n\nThis integration allows you to preview active REPL buffers. Pressing `<CR>`\nwill open the selected REPL buffer using `wincmd`, either with a meta-local\n`wincmd` or the global `wincmd`, depending on the context.\n\nFor users familiar with `Snacks.picker`'s API, custom options can be passed to\nthe function to tailor its behavior, similar to other `Snacks` pickers.\n\n```lua\nrequire('yarepl.extensions.snacks').repl_show {\n    prompt = 'Yarepl REPL',\n}\n```\n"
  },
  {
    "path": "lua/telescope/_extensions/REPLShow.lua",
    "content": "local finders = require 'telescope.finders'\nlocal pickers = require 'telescope.pickers'\n\nlocal conf = require('telescope.config').values\n\nlocal function REPLShow(opts)\n    -- Deprecate REPLShow in favor of yarepl_show\n    vim.deprecate('REPLShow', 'yarepl_show', '2026-06-01', 'yarepl.nvim', false)\n    vim.cmd.REPLCleanup()\n\n    local repls = require('yarepl')._repls\n    local buffers = {}\n    for _, repl in ipairs(repls) do\n        table.insert(buffers, { bufnr = repl.bufnr, name = vim.api.nvim_buf_get_name(repl.bufnr) })\n    end\n    if #buffers == 0 then\n        return\n    end\n\n    local function focus_repl(prompt_bufnr)\n        local actions = require 'telescope.actions'\n        local action_state = require 'telescope.actions.state'\n        local selection = action_state.get_selected_entry()\n        if not selection then\n            return\n        end\n\n        for id, repl in ipairs(repls) do\n            if repl.bufnr == selection.bufnr then\n                actions.close(prompt_bufnr)\n                -- Open the REPL buffer with configured wincmd.\n                vim.cmd(id .. 'REPLFocus')\n                return\n            end\n        end\n    end\n\n    pickers\n        .new(opts, {\n            prompt_title = 'REPL Buffers',\n            finder = finders.new_table {\n                results = buffers,\n                entry_maker = function(entry)\n                    return {\n                        value = entry.name,\n                        display = ' ' .. entry.name,\n                        ordinal = entry.name,\n                        bufnr = entry.bufnr,\n                        lnum = vim.api.nvim_buf_line_count(entry.bufnr),\n                    }\n                end,\n            },\n            previewer = conf.grep_previewer(opts),\n            sorter = conf.generic_sorter(opts),\n            default_selection_index = 1,\n            attach_mappings = function(_, _)\n                local actions = require 'telescope.actions'\n                actions.select_default:replace(focus_repl)\n                return true\n            end,\n        })\n        :find()\nend\n\nreturn require('telescope').register_extension {\n    exports = {\n        REPLShow = REPLShow,\n    },\n}\n"
  },
  {
    "path": "lua/telescope/_extensions/yarepl_show.lua",
    "content": "local finders = require 'telescope.finders'\nlocal pickers = require 'telescope.pickers'\n\nlocal conf = require('telescope.config').values\n\nlocal function yarepl_show(opts)\n    vim.cmd 'Yarepl cleanup'\n\n    local repls = require('yarepl')._repls\n    local buffers = {}\n    for _, repl in ipairs(repls) do\n        table.insert(buffers, { bufnr = repl.bufnr, name = vim.api.nvim_buf_get_name(repl.bufnr) })\n    end\n    if #buffers == 0 then\n        return\n    end\n\n    local function focus_repl(prompt_bufnr)\n        local actions = require 'telescope.actions'\n        local action_state = require 'telescope.actions.state'\n        local selection = action_state.get_selected_entry()\n        if not selection then\n            return\n        end\n\n        for id, repl in ipairs(repls) do\n            if repl.bufnr == selection.bufnr then\n                actions.close(prompt_bufnr)\n                -- Open the REPL buffer with configured wincmd.\n                vim.cmd(id .. 'Yarepl focus')\n                return\n            end\n        end\n    end\n\n    pickers\n        .new(opts, {\n            prompt_title = 'REPL Buffers',\n            finder = finders.new_table {\n                results = buffers,\n                entry_maker = function(entry)\n                    return {\n                        value = entry.name,\n                        display = ' ' .. entry.name,\n                        ordinal = entry.name,\n                        bufnr = entry.bufnr,\n                        lnum = vim.api.nvim_buf_line_count(entry.bufnr),\n                    }\n                end,\n            },\n            previewer = conf.grep_previewer(opts),\n            sorter = conf.generic_sorter(opts),\n            default_selection_index = 1,\n            attach_mappings = function(_, _)\n                local actions = require 'telescope.actions'\n                actions.select_default:replace(focus_repl)\n                return true\n            end,\n        })\n        :find()\nend\n\nreturn require('telescope').register_extension {\n    exports = {\n        yarepl_show = yarepl_show,\n    },\n}\n"
  },
  {
    "path": "lua/yarepl/extensions/aider.lua",
    "content": "local keymap = vim.api.nvim_set_keymap\nlocal util = require 'yarepl.extensions.utility'\n\nlocal M = {}\n\nlocal function default_wincmd(bufnr, name)\n    local winid = vim.api.nvim_open_win(bufnr, true, {\n        relative = 'laststatus',\n        row = 0,\n        col = math.floor(vim.o.columns * 0.5),\n        width = math.floor(vim.o.columns * 0.5),\n        height = math.floor(vim.o.lines * 0.7),\n        style = 'minimal',\n        title = name,\n        border = 'rounded',\n        title_pos = 'center',\n    })\n    if M.config.show_winbar_in_float_window then\n        vim.wo[winid].winbar = '%t'\n    end\nend\n\n-- Predefined prefix setters\nlocal prefixes = {\n    '',\n    '/add',\n    '/architect',\n    '/ask',\n    '/chat-mode',\n    '/clear',\n    '/code',\n    '/commit',\n    '/copy',\n    '/copy-context',\n    '/diff',\n    '/drop',\n    '/editor',\n    '/exit',\n    '/git',\n    '/help',\n    '/lint',\n    '/load',\n    '/ls',\n    '/map',\n    '/map-refresh',\n    '/model',\n    '/models',\n    '/multiline-mode',\n    '/paste',\n    '/quit',\n    '/read-only',\n    '/report',\n    '/reset',\n    '/run',\n    '/save',\n    '/settings',\n    '/test',\n    '/tokens',\n    '/undo',\n    '/voice',\n    '/web',\n    '/think-tokens',\n    '/reasoning-effort',\n    '/editor-model',\n    '/weak-model',\n    '/editor',\n    '/edit',\n    '/context',\n}\n\nlocal aider_args = {\n    '--reasoning-effort',\n    '--watch-files',\n    '--model',\n    '--opus',\n    '--sonnet',\n    '--4',\n    '--4o',\n    '--mini',\n    '--4-turbo',\n    '--35turbo',\n    '--deepseek',\n    '--o1-mini',\n    '--o1-preview',\n    '--architect',\n    '--weak-model',\n    '--editor-model',\n    '--editor-edit-format',\n    '--show-model-warnings',\n    '--no-show-model-warnings',\n    '--cache-prompts',\n    '--no-cache-prompts',\n    '--map-refresh',\n    '--map-multiplier-no-files',\n    '--restore-chat-history',\n    '--no-restore-chat-history',\n    '--pretty',\n    '--no-pretty',\n    '--stream',\n    '--no-stream',\n    '--user-input-color',\n    '--tool-output-color',\n    '--tool-error-color',\n    '--tool-warning-color',\n    '--assistant-output-color',\n    '--completion-menu-color',\n    '--completion-menu-bg-color',\n    '--completion-menu-current-color',\n    '--completion-menu-current-bg-color',\n    '--code-theme',\n    '--show-diffs',\n    '--git',\n    '--no-git',\n    '--gitignore',\n    '--no-gitignore',\n    '--aiderignore',\n    '--subtree-only',\n    '--auto-commits',\n    '--no-auto-commits',\n    '--dirty-commits',\n    '--no-dirty-commits',\n    '--attribute-author',\n    '--no-attribute-author',\n    '--attribute-committer',\n    '--no-attribute-committer',\n    '--attribute-commit-message-author',\n    '--no-attribute-commit-message-author',\n    '--attribute-commit-message-committer',\n    '--no-attribute-commit-message-committer',\n    '--commit',\n    '--commit-prompt',\n    '--dry-run',\n    '--no-dry-run',\n    '--skip-sanity-check-repo',\n    '--lint',\n    '--lint-cmd',\n    '--auto-lint',\n    '--no-auto-lint',\n    '--test-cmd',\n    '--auto-test',\n    '--no-auto-test',\n    '--test',\n    '--file',\n    '--read',\n    '--vim',\n    '--chat-language',\n    '--install-main-branch',\n    '--apply',\n    '--yes-always',\n    '-v',\n    '--show-repo-map',\n    '--show-prompts',\n    '--message',\n    '--message-file',\n    '--encoding',\n    '-c',\n    '--gui',\n    '--suggest-shell-commands',\n    '--no-suggest-shell-commands',\n    '--voice-format',\n    '--voice-language',\n    '--multiline',\n    '--reasoning-effort',\n    '--thinking-tokens',\n    '--auto-accept-architect',\n    '--no-auto-accept-architect',\n}\n\n-- Create a closure for prefix handling\nlocal function create_prefix_handler()\n    local yarepl = require 'yarepl'\n    local current_prefix = ''\n\n    local add_prefix = function(strings)\n        if #current_prefix > 0 and #strings > 0 then\n            strings[1] = current_prefix .. ' ' .. strings[1]\n        end\n\n        return yarepl.formatter.bracketed_pasting(strings)\n    end\n\n    return {\n        set_prefix = function(prefix)\n            if not vim.tbl_contains(prefixes, prefix) then\n                vim.notify('Unknown prefix for aider: ' .. prefix, vim.log.levels.WARN)\n                return\n            end\n            current_prefix = prefix\n        end,\n        formatter = add_prefix,\n    }\nend\n\n-- Initialize the prefix handler\nlocal prefix_handler = create_prefix_handler()\n\nM.set_prefix = prefix_handler.set_prefix\nM.config = {\n    show_winbar_in_float_window = true,\n    wincmd = default_wincmd,\n    formatter = prefix_handler.formatter,\n    aider_args = { '--watch-files' },\n    aider_cmd = 'aider',\n}\n\nM.setup = function(params)\n    M.config = vim.tbl_deep_extend('force', M.config, params or {})\nend\n\nM.create_aider_meta = function()\n    return {\n        cmd = function()\n            local args\n            -- build up the command to launch aider based on M.config.aider_args\n            -- (the command line options) and the M.config.aider_cmd.\n            if type(M.config.aider_cmd) == 'string' then\n                args = vim.deepcopy(M.config.aider_args)\n                table.insert(args, 1, M.config.aider_cmd)\n            elseif type(M.config.aider_cmd) == 'table' then\n                args = vim.deepcopy(M.config.aider_cmd)\n                for _, arg in ipairs(M.config.aider_args) do\n                    table.insert(args, arg)\n                end\n            else\n                vim.notify('invalid aider cmd type', vim.log.levels.ERROR)\n                return\n            end\n\n            return args\n        end,\n        formatter = M.config.formatter,\n        wincmd = M.config.wincmd,\n    }\nend\n\nlocal shortcuts = {\n    { name = 'send_yes', legacy_name = 'Yes', key = 'y' },\n    { name = 'send_no', legacy_name = 'No', key = 'n' },\n    { name = 'send_abort', legacy_name = 'Abort', key = '\\3' }, -- Ctrl-c\n    { name = 'send_exit', legacy_name = 'Exit', key = '\\4' }, -- Ctrl-d\n    { name = 'send_diff', legacy_name = 'Diff', key = '/diff' },\n    { name = 'send_paste', legacy_name = 'Paste', key = '/paste' },\n    { name = 'send_clear', legacy_name = 'Clear', key = '/clear' },\n    { name = 'send_undo', legacy_name = 'Undo', key = '/undo' },\n    { name = 'send_reset', legacy_name = 'Reset', key = '/reset' },\n    { name = 'send_drop', legacy_name = 'Drop', key = '/drop' },\n    { name = 'send_ls', legacy_name = 'Ls', key = '/ls' },\n    { name = 'send_ask_mode', legacy_name = 'AskMode', key = '/ask' },\n    { name = 'send_arch_mode', legacy_name = 'ArchMode', key = '/architect' },\n    { name = 'send_code_mode', legacy_name = 'CodeMode', key = '/code' },\n    { name = 'send_context_mode', legacy_name = 'ContextMode', key = '/context' },\n}\n\n-------------------------------------\n-- New unified Yarepl aider commands\n-------------------------------------\n\nlocal aider_commands = {}\nlocal aider_completions = {}\n\nfor _, shortcut in ipairs(shortcuts) do\n    aider_commands[shortcut.name] = function(opts)\n        local id = opts.count\n        util.send_to_repl_raw('aider', id, shortcut.key .. '\\r')\n    end\n    aider_completions[shortcut.name] = true\nend\n\naider_commands.set_args = function(opts)\n    M.config.aider_args = opts.fargs or {}\nend\naider_completions.set_args = function()\n    return aider_args\nend\n\naider_commands.set_prefix = function(opts)\n    local prefix = opts.args\n\n    if prefix == '' then\n        vim.ui.select(prefixes, {\n            prompt = 'Select prefix: ',\n        }, function(choice)\n            if not choice then\n                return\n            end\n\n            M.set_prefix(choice)\n        end)\n    else\n        M.set_prefix(prefix)\n    end\nend\naider_completions.set_prefix = function()\n    return prefixes\nend\n\naider_commands.remove_prefix = function()\n    M.set_prefix ''\nend\naider_completions.remove_prefix = true\n\naider_commands.exec = function(opts)\n    local id = opts.count\n    local command = opts.args\n    util.send_to_repl_raw('aider', id, command .. '\\r')\nend\naider_completions.exec = function()\n    return prefixes\nend\n\nlocal yarepl = require 'yarepl'\n\nyarepl.commands.aider = function(opts)\n    local fargs = opts.fargs\n    if #fargs == 0 then\n        vim.notify('Yarepl aider: subcommand required', vim.log.levels.ERROR)\n        return\n    end\n\n    local subcmd = table.remove(fargs, 1)\n    local handler = aider_commands[subcmd]\n    if not handler then\n        vim.notify('Yarepl aider: unknown subcommand: ' .. subcmd, vim.log.levels.ERROR)\n        return\n    end\n\n    handler { args = table.concat(fargs, ' '), fargs = fargs, count = opts.count, bang = opts.bang }\nend\n\nyarepl.completions.aider = aider_completions\n\n-------------------------------------\n-- New <Plug(yarepl-aider-*) keymaps\n-------------------------------------\n\nfor _, shortcut in ipairs(shortcuts) do\n    local plug_name = shortcut.name:gsub('_', '-')\n    keymap('n', '<Plug>(yarepl-aider-' .. plug_name .. ')', '', {\n        noremap = true,\n        callback = function()\n            util.run_cmd_with_count('Yarepl aider ' .. shortcut.name)\n        end,\n    })\nend\n\nkeymap('n', '<Plug>(yarepl-aider-exec)', '', {\n    noremap = true,\n    callback = function()\n        return util.partial_cmd_with_count_expr 'Yarepl aider exec '\n    end,\n    expr = true,\n})\n\n-------------------------------------\n-- Legacy commands with deprecation notices\n-------------------------------------\n\nvim.api.nvim_create_user_command('AiderSetArgs', function(opts)\n    vim.deprecate('AiderSetArgs', 'Yarepl aider set_args', '2026-06-01', 'yarepl.nvim', false)\n    M.config.aider_args = opts.fargs or {}\nend, {\n    nargs = '*',\n    complete = function()\n        return aider_args\n    end,\n})\n\nvim.api.nvim_create_user_command('AiderSetPrefix', function(opts)\n    vim.deprecate('AiderSetPrefix', 'Yarepl aider set_prefix', '2026-06-01', 'yarepl.nvim', false)\n    local prefix = opts.args\n\n    if prefix == '' then\n        vim.ui.select(prefixes, {\n            prompt = 'Select prefix: ',\n        }, function(choice)\n            if not choice then\n                return\n            end\n\n            M.set_prefix(choice)\n        end)\n    else\n        M.set_prefix(prefix)\n    end\nend, {\n    nargs = '?',\n    complete = function()\n        return prefixes\n    end,\n})\n\nvim.api.nvim_create_user_command('AiderRemovePrefix', function()\n    vim.deprecate('AiderRemovePrefix', 'Yarepl aider remove_prefix', '2026-06-01', 'yarepl.nvim', false)\n    M.set_prefix ''\nend, {})\n\nfor _, shortcut in ipairs(shortcuts) do\n    vim.api.nvim_create_user_command('AiderSend' .. shortcut.legacy_name, function(opts)\n        vim.deprecate(\n            'AiderSend' .. shortcut.legacy_name,\n            'Yarepl aider ' .. shortcut.name,\n            '2026-06-01',\n            'yarepl.nvim',\n            false\n        )\n        local id = opts.count\n        util.send_to_repl_raw('aider', id, shortcut.key .. '\\r')\n    end, { count = true })\nend\n\nvim.api.nvim_create_user_command('AiderExec', function(opts)\n    vim.deprecate('AiderExec', 'Yarepl aider exec', '2026-06-01', 'yarepl.nvim', false)\n    local id = opts.count\n    local command = opts.args\n    util.send_to_repl_raw('aider', id, command .. '\\r')\nend, {\n    count = true,\n    nargs = '*',\n    complete = function()\n        return prefixes\n    end,\n})\n\n-------------------------------------\n-- Legacy <Plug>(Aider*) keymaps with deprecation notices\n-------------------------------------\n\nfor _, shortcut in ipairs(shortcuts) do\n    local old_plug = '<Plug>(AiderSend' .. shortcut.legacy_name .. ')'\n    local new_plug = '<Plug>(yarepl-aider-' .. shortcut.name:gsub('_', '-') .. ')'\n    keymap('n', old_plug, '', {\n        noremap = true,\n        callback = function()\n            vim.deprecate(old_plug, new_plug, '2026-06-01', 'yarepl.nvim', false)\n            util.run_cmd_with_count('AiderSend' .. shortcut.legacy_name)\n        end,\n    })\nend\n\nkeymap('n', '<Plug>(AiderExec)', '', {\n    noremap = true,\n    callback = function()\n        vim.deprecate('<Plug>(AiderExec)', '<Plug>(yarepl-aider-exec)', '2026-06-01', 'yarepl.nvim', false)\n        return util.partial_cmd_with_count_expr 'AiderExec'\n    end,\n    expr = true,\n})\n\nreturn M\n"
  },
  {
    "path": "lua/yarepl/extensions/code_cell.lua",
    "content": "local M = {}\n\nlocal autocmd = vim.api.nvim_create_autocmd\nlocal augroup = vim.api.nvim_create_augroup('yarepl.code_cell', {})\nlocal bufmap = vim.api.nvim_buf_set_keymap\n\nfunction M.textobj_code_cell(around_or_inner, start_pattern, end_pattern)\n    local has_same_start_end_pattern = start_pattern == end_pattern\n    -- \\22 is Ctrl-V\n    local is_in_visual_mode = vim.tbl_contains({ 'v', 'V', '\\22' }, vim.fn.mode())\n\n    -- send `<ESC>` key to clear visual marks such that we can update the\n    -- visual range.\n    if is_in_visual_mode then\n        vim.api.nvim_feedkeys('\\27', 'nx', false)\n    end\n\n    local row = vim.api.nvim_win_get_cursor(0)[1]\n    local max_row = vim.api.nvim_buf_line_count(0)\n\n    -- nvim_buf_get_lines is 0 indexed, while nvim_win_get_cursor is 1 indexed\n    local chunk_start = nil\n\n    for row_idx = row, 1, -1 do\n        local line_content = vim.api.nvim_buf_get_lines(0, row_idx - 1, row_idx, false)[1]\n\n        -- upward searching if find the end_pattern first which means\n        -- the cursor pos is not in a chunk, then early return\n        -- this method only works when start and end pattern are not same\n        ---@diagnostic disable-next-line undefined-filed\n        if not has_same_start_end_pattern and line_content:match(end_pattern) then\n            return\n        end\n\n        ---@diagnostic disable-next-line undefined-filed\n        if line_content:match(start_pattern) then\n            chunk_start = row_idx\n            break\n        end\n    end\n\n    -- if find chunk_start then find chunk_end\n    local chunk_end = nil\n\n    if chunk_start then\n        if chunk_start == max_row then\n            return\n        end\n\n        for row_idx = chunk_start + 1, max_row, 1 do\n            local line_content = vim.api.nvim_buf_get_lines(0, row_idx - 1, row_idx, false)[1]\n\n            ---@diagnostic disable-next-line undefined-filed\n            if line_content:match(end_pattern) then\n                chunk_end = row_idx\n                break\n            end\n        end\n    end\n\n    if chunk_start and chunk_end then\n        if around_or_inner == 'i' then\n            vim.api.nvim_win_set_cursor(0, { chunk_start + 1, 0 })\n            local internal_length = chunk_end - chunk_start - 2\n            if internal_length == 0 then\n                vim.cmd.normal { 'V', bang = true }\n            elseif internal_length > 0 then\n                vim.cmd.normal { 'V' .. internal_length .. 'j', bang = true }\n            end\n        end\n\n        if around_or_inner == 'a' then\n            vim.api.nvim_win_set_cursor(0, { chunk_start, 0 })\n            local chunk_length = chunk_end - chunk_start\n            vim.cmd.normal { 'V' .. chunk_length .. 'j', bang = true }\n        end\n    end\nend\n\nfunction M.set_code_cell_keymaps(start_pattern, end_pattern, key, desc)\n    for _, mode in ipairs { 'o', 'x' } do\n        for _, around_or_inner in ipairs { 'a', 'i' } do\n            bufmap(0, mode, around_or_inner .. key, '', {\n                silent = true,\n                desc = desc,\n                callback = function()\n                    M.textobj_code_cell(around_or_inner, start_pattern, end_pattern)\n                end,\n            })\n        end\n    end\nend\n\nfunction M.register_text_objects(options)\n    for _, opt in ipairs(options) do\n        autocmd('FileType', {\n            group = augroup,\n            desc = 'Setup yarepl code cell text objects: ' .. opt.desc,\n            callback = function()\n                M.set_code_cell_keymaps(opt.start_pattern, opt.end_pattern, opt.key, opt.desc)\n            end,\n            pattern = opt.ft,\n        })\n    end\nend\n\nreturn M\n"
  },
  {
    "path": "lua/yarepl/extensions/codex.lua",
    "content": "local keymap = vim.api.nvim_set_keymap\nlocal util = require 'yarepl.extensions.utility'\n\nlocal M = {}\n\nlocal function default_wincmd(bufnr, name)\n    local winid = vim.api.nvim_open_win(bufnr, true, {\n        relative = 'laststatus',\n        row = 0,\n        col = math.floor(vim.o.columns * 0.5),\n        width = math.floor(vim.o.columns * 0.5),\n        height = math.floor(vim.o.lines * 0.7),\n        style = 'minimal',\n        title = name,\n        border = 'rounded',\n        title_pos = 'center',\n    })\n    if M.config.show_winbar_in_float_window then\n        vim.wo[winid].winbar = '%t'\n    end\nend\n\nlocal prefixes = {\n    '/model',\n    '/approvals',\n    '/init',\n    '/new',\n    '/compact',\n    '/diff',\n    '/mention',\n    '/status',\n}\n\nlocal codex_args = {\n    '--config',\n    '--image',\n    '--model',\n    '--oss',\n    '--profile',\n    '--sandbox',\n    '--ask-for-approval',\n    '--full-auto',\n    '--dangerously-bypass-approvals-and-sandbox',\n    '--cd',\n}\n\nM.config = {\n    show_winbar_in_float_window = true,\n    wincmd = default_wincmd,\n    source_syntax = 'read the instruction from {{file}}',\n    codex_args = {},\n    formatter = 'bracketed_pasting_delayed_cr',\n    codex_cmd = 'codex',\n    warn_on_EDITOR_env_var = true,\n}\n\nM.setup = function(params)\n    M.config = vim.tbl_deep_extend('force', M.config, params or {})\nend\n\nM.create_codex_meta = function()\n    return {\n        cmd = function()\n            local args\n            -- build up the command to launch codex based on M.config.codex_args\n            -- (the command line options) and the M.config.codex_cmd.\n            if type(M.config.codex_cmd) == 'string' then\n                args = vim.deepcopy(M.config.codex_args)\n                table.insert(args, 1, M.config.codex_cmd)\n            elseif type(M.config.codex_cmd) == 'table' then\n                args = vim.deepcopy(M.config.codex_cmd)\n                for _, arg in ipairs(M.config.codex_args) do\n                    table.insert(args, arg)\n                end\n            else\n                vim.notify('invalid codex cmd type', vim.log.levels.ERROR)\n                return\n            end\n\n            return args\n        end,\n        formatter = M.config.formatter,\n        wincmd = M.config.wincmd,\n        source_syntax = M.config.source_syntax,\n        send_delayed_final_cr = true,\n    }\nend\n\nlocal shortcuts = {\n    -- Ctrl-c\n    { name = 'send_abort', legacy_name = 'Abort', key = '\\3', requires_cr = false },\n    -- Ctrl-d\n    { name = 'send_exit', legacy_name = 'Exit', key = '\\4', requires_cr = false },\n    { name = 'send_diff', legacy_name = 'Diff', key = '/diff', requires_cr = true },\n    { name = 'send_status', legacy_name = 'Status', key = '/status', requires_cr = true },\n    { name = 'send_model', legacy_name = 'Model', key = '/model', requires_cr = true },\n    { name = 'send_new', legacy_name = 'New', key = '/new', requires_cr = true },\n    { name = 'send_approvals', legacy_name = 'Approvals', key = '/approvals', requires_cr = true },\n    { name = 'send_compact', legacy_name = 'Compact', key = '/compact', requires_cr = true },\n    -- Ctrl-g\n    {\n        name = 'send_open_editor',\n        legacy_name = 'OpenEditor',\n        key = '\\7',\n        requires_cr = false,\n        pre_hook = function()\n            if M.config.warn_on_EDITOR_env_var and ((not vim.env.EDITOR) or (not vim.env.EDITOR:find 'nvr')) then\n                vim.notify('current $EDITOR command is not nvr, please consider using nvr', vim.log.levels.WARN)\n            end\n        end,\n    },\n    --Ctrl-t\n    { name = 'send_transcript_enter', legacy_name = 'TranscriptEnter', key = '\\20', requires_cr = false },\n    { name = 'send_transcript_quit', legacy_name = 'TranscriptQuit', key = 'q', requires_cr = false },\n    -- Home\n    { name = 'send_transcript_begin', legacy_name = 'TranscriptBegin', key = '\\27[1~', requires_cr = false },\n    -- End\n    { name = 'send_transcript_end', legacy_name = 'TranscriptEnd', key = '\\27[4~', requires_cr = false },\n    { name = 'send_page_up', legacy_name = 'PageUp', key = '\\27[5~', requires_cr = false },\n    { name = 'send_page_down', legacy_name = 'PageDown', key = '\\27[6~', requires_cr = false },\n}\n\n-------------------------------------\n-- New unified Yarepl codex commands\n-------------------------------------\n\nlocal codex_commands = {}\nlocal codex_completions = {}\n\nfor _, shortcut in ipairs(shortcuts) do\n    codex_commands[shortcut.name] = function(opts)\n        if type(shortcut.pre_hook) == 'function' then\n            shortcut.pre_hook()\n        end\n        local id = opts.count\n        util.send_to_repl_raw('codex', id, shortcut.key, shortcut.requires_cr)\n    end\n    codex_completions[shortcut.name] = true\nend\n\ncodex_commands.set_args = function(opts)\n    M.config.codex_args = opts.fargs or {}\nend\ncodex_completions.set_args = function()\n    return codex_args\nend\n\ncodex_commands.exec = function(opts)\n    local id = opts.count\n    local command = opts.args\n    util.send_to_repl_raw('codex', id, command, true)\nend\ncodex_completions.exec = function()\n    return prefixes\nend\n\nlocal yarepl = require 'yarepl'\n\nyarepl.commands.codex = function(opts)\n    local fargs = opts.fargs\n    if #fargs == 0 then\n        vim.notify('Yarepl codex: subcommand required', vim.log.levels.ERROR)\n        return\n    end\n\n    local subcmd = table.remove(fargs, 1)\n    local handler = codex_commands[subcmd]\n    if not handler then\n        vim.notify('Yarepl codex: unknown subcommand: ' .. subcmd, vim.log.levels.ERROR)\n        return\n    end\n\n    handler { args = table.concat(fargs, ' '), fargs = fargs, count = opts.count, bang = opts.bang }\nend\n\nyarepl.completions.codex = codex_completions\n\n-------------------------------------\n-- New <Plug(yarepl-codex-*) keymaps\n-------------------------------------\n\nfor _, shortcut in ipairs(shortcuts) do\n    local plug_name = shortcut.name:gsub('_', '-')\n    keymap('n', '<Plug>(yarepl-codex-' .. plug_name .. ')', '', {\n        noremap = true,\n        callback = function()\n            util.run_cmd_with_count('Yarepl codex ' .. shortcut.name)\n        end,\n    })\nend\n\nkeymap('n', '<Plug>(yarepl-codex-exec)', '', {\n    noremap = true,\n    callback = function()\n        return util.partial_cmd_with_count_expr 'Yarepl codex exec '\n    end,\n    expr = true,\n})\n\n-------------------------------------\n-- Legacy commands with deprecation notices\n-------------------------------------\n\nvim.api.nvim_create_user_command('CodexSetArgs', function(opts)\n    vim.deprecate('CodexSetArgs', 'Yarepl codex set_args', '2026-06-01', 'yarepl.nvim', false)\n    M.config.codex_args = opts.fargs or {}\nend, {\n    nargs = '*',\n    complete = function()\n        return codex_args\n    end,\n})\n\nfor _, shortcut in ipairs(shortcuts) do\n    vim.api.nvim_create_user_command('CodexSend' .. shortcut.legacy_name, function(opts)\n        vim.deprecate(\n            'CodexSend' .. shortcut.legacy_name,\n            'Yarepl codex ' .. shortcut.name,\n            '2026-06-01',\n            'yarepl.nvim',\n            false\n        )\n        if type(shortcut.pre_hook) == 'function' then\n            shortcut.pre_hook()\n        end\n        local id = opts.count\n        util.send_to_repl_raw('codex', id, shortcut.key, shortcut.requires_cr)\n    end, { count = true })\nend\n\nvim.api.nvim_create_user_command('CodexExec', function(opts)\n    vim.deprecate('CodexExec', 'Yarepl codex exec', '2026-06-01', 'yarepl.nvim', false)\n    local id = opts.count\n    local command = opts.args\n    util.send_to_repl_raw('codex', id, command, true)\nend, {\n    count = true,\n    nargs = '*',\n    complete = function()\n        return prefixes\n    end,\n})\n\n-------------------------------------\n-- Legacy <Plug>(Codex*) keymaps with deprecation notices\n-------------------------------------\n\nfor _, shortcut in ipairs(shortcuts) do\n    local old_plug = '<Plug>(CodexSend' .. shortcut.legacy_name .. ')'\n    local new_plug = '<Plug>(yarepl-codex-' .. shortcut.name:gsub('_', '-') .. ')'\n    keymap('n', old_plug, '', {\n        noremap = true,\n        callback = function()\n            vim.deprecate(old_plug, new_plug, '2026-06-01', 'yarepl.nvim', false)\n            util.run_cmd_with_count('CodexSend' .. shortcut.legacy_name)\n        end,\n    })\nend\n\nkeymap('n', '<Plug>(CodexExec)', '', {\n    noremap = true,\n    callback = function()\n        vim.deprecate('<Plug>(CodexExec)', '<Plug>(yarepl-codex-exec)', '2026-06-01', 'yarepl.nvim', false)\n        return util.partial_cmd_with_count_expr 'CodexExec'\n    end,\n    expr = true,\n})\n\nreturn M\n"
  },
  {
    "path": "lua/yarepl/extensions/fzf.lua",
    "content": "local fzf = require 'fzf-lua'\nlocal builtin = require 'fzf-lua.previewer.builtin'\n\nlocal Previewer = builtin.buffer_or_file:extend()\n\nfunction Previewer:new(o, opts, fzf_win)\n    Previewer.super.new(self, o, opts, fzf_win)\n    setmetatable(self, Previewer)\n    return self\nend\n\nlocal function get_buf_name_without_dir(bufnr)\n    return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ':t')\nend\n\nfunction Previewer:parse_entry(entry_str)\n    local repls = require('yarepl')._repls\n\n    for _, repl in ipairs(repls) do\n        if get_buf_name_without_dir(repl.bufnr) == entry_str then\n            return { bufnr = repl.bufnr, path = entry_str }\n        end\n    end\n\n    return { path = entry_str }\nend\n\nlocal repl_show = function(opts)\n    local repls = require('yarepl')._repls\n    local buffers = {}\n    for _, repl in ipairs(repls) do\n        table.insert(buffers, get_buf_name_without_dir(repl.bufnr))\n    end\n    if #buffers == 0 then\n        return\n    end\n\n    local default_opts = {}\n    default_opts.previewer = Previewer\n    default_opts.actions = {\n        ['default'] = function(e)\n            local entry_str = e[1]\n\n            for id, repl in ipairs(repls) do\n                if get_buf_name_without_dir(repl.bufnr) == entry_str then\n                    -- the default action is to open the REPL buffer with configured wincmd\n                    vim.cmd(id .. 'Yarepl focus')\n                    return\n                end\n            end\n        end,\n    }\n\n    opts = vim.tbl_deep_extend('force', default_opts, opts or {})\n\n    fzf.fzf_exec(buffers, opts)\nend\n\nlocal M = { repl_show = repl_show }\n\nreturn M\n"
  },
  {
    "path": "lua/yarepl/extensions/opencode.lua",
    "content": "local keymap = vim.api.nvim_set_keymap\nlocal util = require 'yarepl.extensions.utility'\n\nlocal M = {}\n\nlocal function default_wincmd(bufnr, name)\n    local winid = vim.api.nvim_open_win(bufnr, true, {\n        relative = 'laststatus',\n        row = 0,\n        col = math.floor(vim.o.columns * 0.5),\n        width = math.floor(vim.o.columns * 0.5),\n        height = math.floor(vim.o.lines * 0.7),\n        style = 'minimal',\n        title = name,\n        border = 'rounded',\n        title_pos = 'center',\n    })\n    if M.config.show_winbar_in_float_window then\n        vim.wo[winid].winbar = '%t'\n    end\nend\n\nlocal opencode_args = {\n    '--continue',\n    '--session',\n    '--fork',\n    '--prompt',\n    '--agent',\n    '--model',\n    '--pure',\n    '--print-logs',\n    '--log-level',\n    '--port',\n    '--hostname',\n    '--mdns',\n    '--mdns-domain',\n    '--cors',\n    '--help',\n}\n\nlocal slash_commands = {\n    '/clear',\n    '/compact',\n    '/connect',\n    '/continue',\n    '/editor',\n    '/exit',\n    '/export',\n    '/help',\n    '/init',\n    '/models',\n    '/new',\n    '/q',\n    '/quit',\n    '/redo',\n    '/resume',\n    '/sessions',\n    '/share',\n    '/summarize',\n    '/themes',\n    '/thinking',\n    '/undo',\n    '/unshare',\n}\n\nM.config = {\n    show_winbar_in_float_window = true,\n    wincmd = default_wincmd,\n    formatter = 'bracketed_pasting_delayed_cr',\n    opencode_args = {},\n    opencode_cmd = 'opencode',\n    warn_on_EDITOR_env_var = true,\n}\n\nM.setup = function(params)\n    M.config = vim.tbl_deep_extend('force', M.config, params or {})\nend\n\nM.create_opencode_meta = function()\n    return {\n        cmd = function()\n            local args\n            if type(M.config.opencode_cmd) == 'string' then\n                args = vim.deepcopy(M.config.opencode_args)\n                table.insert(args, 1, M.config.opencode_cmd)\n            elseif type(M.config.opencode_cmd) == 'table' then\n                args = vim.deepcopy(M.config.opencode_cmd)\n                for _, arg in ipairs(M.config.opencode_args) do\n                    table.insert(args, arg)\n                end\n            else\n                vim.notify('invalid opencode cmd type', vim.log.levels.ERROR)\n                return\n            end\n\n            return args\n        end,\n        formatter = M.config.formatter,\n        wincmd = M.config.wincmd,\n        send_delayed_final_cr = true,\n    }\nend\n\nlocal shortcuts = {\n    { name = 'send_compact', key = '/compact', requires_cr = true },\n    { name = 'send_connect', key = '/connect', requires_cr = true },\n    {\n        name = 'send_open_editor',\n        key = '\\24e',\n        requires_cr = false,\n        pre_hook = function()\n            if M.config.warn_on_EDITOR_env_var and ((not vim.env.EDITOR) or (not vim.env.EDITOR:find 'nvr')) then\n                vim.notify('current $EDITOR command is not nvr, please consider using nvr', vim.log.levels.WARN)\n            end\n        end,\n    },\n    { name = 'send_exit', key = '/exit', requires_cr = true },\n    { name = 'send_export', key = '/export', requires_cr = true },\n    { name = 'send_help', key = '/help', requires_cr = true },\n    { name = 'send_init', key = '/init', requires_cr = true },\n    { name = 'send_models', key = '/models', requires_cr = true },\n    { name = 'send_new', key = '/new', requires_cr = true },\n    { name = 'send_redo', key = '/redo', requires_cr = true },\n    { name = 'send_sessions', key = '/sessions', requires_cr = true },\n    { name = 'send_share', key = '/share', requires_cr = true },\n    { name = 'send_thinking', key = '/thinking', requires_cr = true },\n    { name = 'send_undo', key = '/undo', requires_cr = true },\n    { name = 'send_unshare', key = '/unshare', requires_cr = true },\n    { name = 'send_scroll_up', key = '\\27\\21', requires_cr = false },\n    { name = 'send_scroll_down', key = '\\27\\4', requires_cr = false },\n}\n\nlocal opencode_commands = {}\nlocal opencode_completions = {}\n\nfor _, shortcut in ipairs(shortcuts) do\n    opencode_commands[shortcut.name] = function(opts)\n        if type(shortcut.pre_hook) == 'function' then\n            shortcut.pre_hook()\n        end\n        local id = opts.count\n        util.send_to_repl_raw('opencode', id, shortcut.key, shortcut.requires_cr)\n    end\n    opencode_completions[shortcut.name] = true\nend\n\nopencode_commands.exec = function(opts)\n    local id = opts.count\n    local command = opts.args\n    util.send_to_repl_raw('opencode', id, command, true)\nend\n\nopencode_completions.exec = function()\n    return slash_commands\nend\n\nopencode_commands.set_args = function(opts)\n    M.config.opencode_args = opts.fargs or {}\nend\n\nopencode_completions.set_args = function()\n    return opencode_args\nend\n\nlocal yarepl = require 'yarepl'\n\nyarepl.commands.opencode = function(opts)\n    local fargs = opts.fargs\n    if #fargs == 0 then\n        vim.notify('Yarepl opencode: subcommand required', vim.log.levels.ERROR)\n        return\n    end\n\n    local subcmd = table.remove(fargs, 1)\n    local handler = opencode_commands[subcmd]\n    if not handler then\n        vim.notify('Yarepl opencode: unknown subcommand: ' .. subcmd, vim.log.levels.ERROR)\n        return\n    end\n\n    handler { args = table.concat(fargs, ' '), fargs = fargs, count = opts.count, bang = opts.bang }\nend\n\nyarepl.completions.opencode = opencode_completions\n\nfor _, shortcut in ipairs(shortcuts) do\n    local plug_name = shortcut.name:gsub('_', '-')\n    keymap('n', '<Plug>(yarepl-opencode-' .. plug_name .. ')', '', {\n        noremap = true,\n        callback = function()\n            util.run_cmd_with_count('Yarepl opencode ' .. shortcut.name)\n        end,\n    })\nend\n\nkeymap('n', '<Plug>(yarepl-opencode-exec)', '', {\n    noremap = true,\n    callback = function()\n        return util.partial_cmd_with_count_expr 'Yarepl opencode exec '\n    end,\n    expr = true,\n})\n\nreturn M\n"
  },
  {
    "path": "lua/yarepl/extensions/snacks.lua",
    "content": "local M = {}\n\nlocal function get_buf_name_without_dir(bufnr)\n    return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ':t')\nend\n\n---@param opts snacks.picker.Config?\nM.repl_show = function(opts)\n    local has_snacks, snacks = pcall(require, 'snacks.picker')\n    if not has_snacks then\n        vim.notify('Snacks is not installed!', vim.log.levels.ERROR)\n        return\n    end\n\n    local repls = require('yarepl')._repls\n\n    ---@type snacks.picker.Config\n    local source = {\n        finder = function()\n            local items = {}\n\n            for _, repl in ipairs(repls) do\n                table.insert(items, {\n                    buf = repl.bufnr,\n                    text = get_buf_name_without_dir(repl.bufnr),\n                })\n            end\n\n            return items\n        end,\n        format = function(item, _)\n            return { { item.text } }\n        end,\n        confirm = function(picker, item)\n            for id, repl in ipairs(repls) do\n                if repl.bufnr == item.buf then\n                    -- the default action is to open the REPL buffer with configured wincmd\n                    picker:close()\n                    vim.schedule(function()\n                        vim.cmd(id .. 'Yarepl focus')\n                    end)\n                    return\n                end\n            end\n        end,\n    }\n\n    source = vim.tbl_deep_extend('force', source, opts or {})\n\n    snacks.pick(nil, source)\nend\n\nreturn M\n"
  },
  {
    "path": "lua/yarepl/extensions/utility.lua",
    "content": "local M = {}\n\n-- Execute a user command with a count prefix, using the current v:count.\nfunction M.run_cmd_with_count(cmd)\n    require('yarepl').run_cmd_with_count(cmd)\nend\n\n-- Build an expression for mappings that need to pass a count to a user command.\nfunction M.partial_cmd_with_count_expr(cmd)\n    return require('yarepl').partial_cmd_with_count_expr(cmd)\nend\n\n-- Send raw strings to a named REPL\n---@param meta_name string\n---@param id integer\n---@param lines string\n---@param send_delayed_final_cr boolean?\n---@return nil\nfunction M.send_to_repl_raw(meta_name, id, lines, send_delayed_final_cr)\n    local yarepl = require 'yarepl'\n    ---@diagnostic disable-next-line redefined-local\n    local lines = vim.split(lines, '\\r')\n    local bufnr = vim.api.nvim_get_current_buf()\n    yarepl._send_strings(id, meta_name, bufnr, lines, false, false, send_delayed_final_cr)\nend\n\nreturn M\n"
  },
  {
    "path": "lua/yarepl/init.lua",
    "content": "local M = {}\nlocal api = vim.api\nlocal fn = vim.fn\nlocal is_win32 = vim.fn.has 'win32' == 1\n\n---@class yarepl.REPLMeta\n---@field cmd string[]|string|fun(): string|string[] The command to start the REPL, a builtin cmd name (e.g., 'builtin:ipython'), or a function that returns the command\n---@field formatter string|fun(lines: string[]): string[] The formatter name or function to process lines before sending\n---@field source_syntax string The syntax type for sourcing code (e.g., 'python', 'R', 'bash')\n---@field wincmd? string|fun(bufnr: number, name: string) The window command or function to create/focus the REPL window\n---@field source_command_hint? table Configuration for showing source command hints\n---@field send_delayed_final_cr? boolean Whether to send a delayed carriage return after commands\n\n---@class yarepl.REPLInstance\n---@field bufnr number\n---@field term number\n---@field name string\n\nM.formatter = {}\nM.cmd_builtin = {}\nM.commands = {}\nM.completions = {}\nM._virt_text_ns_id = api.nvim_create_namespace 'YareplVirtualText'\n\nlocal default_config = function()\n    return {\n        buflisted = true,\n        scratch = true,\n        ft = 'REPL',\n        wincmd = 'belowright 15 split',\n        ---@type table<string, yarepl.REPLMeta>\n        metas = {\n            aichat = { cmd = 'aichat', formatter = 'bracketed_pasting', source_syntax = 'aichat' },\n            radian = { cmd = 'radian', formatter = 'bracketed_pasting_no_final_new_line', source_syntax = 'R' },\n            ipython = { cmd = 'builtin:ipython', formatter = 'bracketed_pasting', source_syntax = 'ipython' },\n            python = { cmd = 'builtin:python', formatter = 'trim_empty_lines', source_syntax = 'python' },\n            R = { cmd = 'R', formatter = 'trim_empty_lines', source_syntax = 'R' },\n            -- bash version >= 4.4 supports bracketed paste mode. but macos\n            -- shipped with bash 3.2, so we don't use bracketed paste mode for\n            -- macOS\n            bash = {\n                cmd = 'bash',\n                formatter = vim.fn.has 'linux' == 1 and 'bracketed_pasting' or 'trim_empty_lines',\n                source_syntax = 'bash',\n            },\n            zsh = { cmd = 'zsh', formatter = 'bracketed_pasting', source_syntax = 'bash' },\n        },\n        close_on_exit = true,\n        scroll_to_bottom_after_sending = true,\n        -- Format REPL buffer names as #repl_name#n (e.g., #ipython#1) instead of using terminal defaults\n        format_repl_buffers_names = true,\n        highlight_on_send_operator = { enabled = false, hl_group = 'IncSearch', timeout = 150 },\n        os = {\n            windows = {\n                send_delayed_final_cr = true,\n            },\n        },\n        -- Display the first line as virtual text to indicate the actual\n        -- command sent to the REPL.\n        source_command_hint = {\n            enabled = false,\n            hl_group = 'Comment',\n        },\n    }\nend\n\n---@type yarepl.REPLInstance[]\nM._repls = {}\n---@type table<number, yarepl.REPLInstance>\nM._bufnrs_to_repls = {}\n\nlocal function repl_is_valid(repl)\n    return repl ~= nil and api.nvim_buf_is_loaded(repl.bufnr)\nend\n\n-- rearrange repls such that there's no gap in the repls table.\nlocal function repl_cleanup()\n    local valid_repls = {}\n    local valid_repls_id = {}\n    for id, repl in pairs(M._repls) do\n        if repl_is_valid(repl) then\n            table.insert(valid_repls_id, id)\n        end\n    end\n\n    for bufnr, repl in pairs(M._bufnrs_to_repls) do\n        if not repl_is_valid(repl) then\n            M._bufnrs_to_repls[bufnr] = nil\n        end\n\n        if not api.nvim_buf_is_loaded(bufnr) then\n            M._bufnrs_to_repls[bufnr] = nil\n        end\n    end\n\n    table.sort(valid_repls_id)\n\n    for _, id in ipairs(valid_repls_id) do\n        table.insert(valid_repls, M._repls[id])\n    end\n    M._repls = valid_repls\n\n    if M._config.format_repl_buffers_names then\n        for id, repl in pairs(M._repls) do\n            -- to avoid name conflict, we add a temp prefix\n            api.nvim_buf_set_name(repl.bufnr, string.format('#%s#temp#%d', repl.name, id))\n        end\n\n        for id, repl in pairs(M._repls) do\n            api.nvim_buf_set_name(repl.bufnr, string.format('#%s#%d', repl.name, id))\n        end\n    end\nend\n\nlocal function focus_repl(repl)\n    if not repl_is_valid(repl) then\n        -- if id is nil, print it as -1\n        vim.notify [[REPL doesn't exist!]]\n        return\n    end\n    local win = fn.bufwinid(repl.bufnr)\n    if win ~= -1 then\n        api.nvim_set_current_win(win)\n    else\n        local wincmd = M._config.metas[repl.name].wincmd or M._config.wincmd\n\n        if type(wincmd) == 'function' then\n            wincmd(repl.bufnr, repl.name)\n        else\n            vim.cmd(wincmd)\n            api.nvim_set_current_buf(repl.bufnr)\n        end\n    end\nend\n\nlocal function create_repl(id, repl_name)\n    if repl_is_valid(M._repls[id]) then\n        vim.notify(string.format('REPL %d already exists, no new REPL is created', id))\n        return\n    end\n\n    if not M._config.metas[repl_name] then\n        vim.notify 'No REPL palatte is found'\n        return\n    end\n\n    local bufnr = api.nvim_create_buf(M._config.buflisted, M._config.scratch)\n    vim.bo[bufnr].filetype = M._config.ft\n\n    local cmd\n\n    if type(M._config.metas[repl_name].cmd) == 'function' then\n        cmd = M._config.metas[repl_name].cmd()\n    else\n        cmd = M._config.metas[repl_name].cmd\n    end\n\n    local wincmd = M._config.metas[repl_name].wincmd or M._config.wincmd\n\n    if type(wincmd) == 'function' then\n        wincmd(bufnr, repl_name)\n    else\n        vim.cmd(wincmd)\n        api.nvim_set_current_buf(bufnr)\n    end\n\n    local opts = {}\n    opts.on_exit = function()\n        if M._config.close_on_exit then\n            local bufwinid = fn.bufwinid(bufnr)\n            while bufwinid ~= -1 do\n                api.nvim_win_close(bufwinid, true)\n                bufwinid = fn.bufwinid(bufnr)\n            end\n            -- It is possible that this buffer has already been deleted, before\n            -- the process is exit.\n            if api.nvim_buf_is_loaded(bufnr) then\n                api.nvim_buf_delete(bufnr, { force = true })\n            end\n        end\n        repl_cleanup()\n    end\n\n    ---@diagnostic disable-next-line: redefined-local\n    local function termopen(cmd, opts)\n        if vim.fn.has 'nvim-0.11' == 1 then\n            opts.term = true\n            return vim.fn.jobstart(cmd, opts)\n        else\n            ---@diagnostic disable-next-line: deprecated\n            return vim.fn.termopen(cmd, opts)\n        end\n    end\n\n    local term = termopen(cmd, opts)\n    if M._config.format_repl_buffers_names then\n        api.nvim_buf_set_name(bufnr, string.format('#%s#%d', repl_name, id))\n    end\n    M._repls[id] = { bufnr = bufnr, term = term, name = repl_name }\nend\n\n-- get the id of the closest repl whose name is `NAME` from the `ID`\nlocal function find_closest_repl_from_id_with_name(id, name)\n    local closest_id = nil\n    local closest_distance = math.huge\n    for repl_id, repl in pairs(M._repls) do\n        if repl.name == name then\n            local distance = math.abs(repl_id - id)\n            if distance < closest_distance then\n                closest_id = repl_id\n                closest_distance = distance\n            end\n            if distance == 0 then\n                break\n            end\n        end\n    end\n    return closest_id\nend\n\nlocal function repl_swap(id_1, id_2)\n    local repl_1 = M._repls[id_1]\n    local repl_2 = M._repls[id_2]\n    M._repls[id_1] = repl_2\n    M._repls[id_2] = repl_1\n    repl_cleanup()\nend\n\nlocal function find_repl_by_name_index(name, index)\n    local count = 0\n    for _, repl in ipairs(M._repls) do\n        if repl_is_valid(repl) and repl.name == name then\n            count = count + 1\n            if count == index then\n                return repl\n            end\n        end\n    end\n    return nil\nend\n\nlocal function attach_buffer_to_repl(bufnr, repl)\n    if not repl_is_valid(repl) then\n        vim.notify [[REPL doesn't exist!]]\n        return\n    end\n\n    if not api.nvim_buf_is_loaded(bufnr) then\n        vim.notify [[Invalid buffer!]]\n        return\n    end\n    M._bufnrs_to_repls[bufnr] = repl\nend\n\nM.bufnr_is_attached_to_repl = function(bufnr)\n    if not repl_is_valid(M._bufnrs_to_repls[bufnr]) then\n        return false\n    else\n        return true\n    end\nend\n\n---@param id number? the id of the repl,\n---@param name string? the name of the closest repl that will try to find\n---@param bufnr number? the buffer number of the buffer\n---@return yarepl.REPLInstance? repl the repl object or nil if not found\n-- get the repl specified by `id` and `name`. If `id` is 0, then will try to\n-- find the REPL `bufnr` is attached to, if not find, will use `id = 1`. If\n-- `name` is not nil or not an empty string, then will try to find the REPL\n-- with `name` relative to `id`.\nfunction M._get_repl(id, name, bufnr)\n    local has_name = name ~= nil and name ~= ''\n\n    -- No count: prefer the attached REPL; if a name is supplied, require it to match.\n    if id == nil or id == 0 then\n        local attached_repl = M._bufnrs_to_repls[bufnr]\n        if has_name and repl_is_valid(attached_repl) and attached_repl.name == name then\n            return attached_repl\n        end\n        if not has_name and repl_is_valid(attached_repl) then\n            return attached_repl\n        end\n\n        id = 1\n    end\n\n    local repl = M._repls[id]\n\n    if has_name then\n        local closest_id = find_closest_repl_from_id_with_name(id, name)\n        repl = M._repls[closest_id]\n    end\n\n    if repl_is_valid(repl) then\n        return repl\n    end\n    return nil\nend\n\nlocal function repl_win_scroll_to_bottom(repl)\n    if not repl_is_valid(repl) then\n        vim.notify [[REPL doesn't exist!]]\n        return\n    end\n\n    local repl_win = fn.bufwinid(repl.bufnr)\n    if repl_win ~= -1 then\n        local lines = api.nvim_buf_line_count(repl.bufnr)\n        api.nvim_win_set_cursor(repl_win, { lines, 0 })\n    end\nend\n\nlocal function post_create_repl(id, bufnr, opts)\n    if not repl_is_valid(M._repls[id]) then\n        return\n    end\n\n    if opts.bang then\n        attach_buffer_to_repl(bufnr, M._repls[id])\n    end\n\n    if M._config.scroll_to_bottom_after_sending then\n        repl_win_scroll_to_bottom(M._repls[id])\n    end\nend\n\n-- Currently, block-wise sending is not supported.\n---@param mode \"operator\"|\"visual\"\n---@param submode string\nlocal function get_lines(mode, submode)\n    local begin_mark = mode == 'operator' and \"'[\" or \"'<\"\n    local end_mark = mode == 'operator' and \"']\" or \"'>\"\n\n    local begin_pos = fn.getpos(begin_mark)\n    local end_pos = fn.getpos(end_mark)\n\n    local begin_line = begin_pos[2]\n    local begin_col = begin_pos[3]\n    local end_line = end_pos[2]\n    local end_col = end_pos[3]\n\n    -- https://github.com/milanglacier/yarepl.nvim/pull/42 Handle missing,\n    -- empty, or inverted ranges that occur when canceling a leap.nvim motion.\n    if\n        begin_line == 0\n        or end_line == 0\n        or begin_line > end_line\n        or (begin_line == end_line and begin_col > end_col)\n    then\n        return {}\n    end\n\n    if submode == 'char' or submode == 'v' then\n        local lines = api.nvim_buf_get_text(0, begin_line - 1, begin_col - 1, end_line - 1, -1, {})\n        if #lines > 0 and #lines[#lines] > 0 then\n            if begin_line == end_line then\n                end_col = end_col - begin_col + 1\n            end\n            local offset = vim.str_utf_end(lines[#lines], end_col)\n            lines[#lines] = lines[#lines]:sub(1, end_col + offset)\n        end\n        return lines\n    else\n        -- Line-wise mode, or fallback to line-wise for unsupported block-wise mode.\n        return api.nvim_buf_get_lines(0, begin_line - 1, end_line, false)\n    end\nend\n\n---@param motion_type string\nlocal function highlight_range(motion_type)\n    local highlight_config = M._config.highlight_on_send_operator\n\n    local type_map = {\n        line = 'V',\n        char = 'v',\n        block = '\\22', -- Control-V\n        V = 'V',\n        v = 'v',\n        ['\\22'] = '\\22',\n    }\n    local regtype = type_map[motion_type] or 'v'\n\n    vim.highlight.on_yank {\n        higroup = highlight_config.hl_group,\n        timeout = highlight_config.timeout,\n        event = {\n            operator = 'y',\n            regtype = regtype,\n            inclusive = true,\n            visual = false,\n        },\n    }\nend\n\n---Get the formatter function from either a string name or function\n---@param formatter string|function The formatter name or function\n---@return function Formatter function to use\n---@throws string Error if formatter name is unknown\nlocal function get_formatter(formatter)\n    if type(formatter) == 'string' then\n        return M.formatter[formatter] or error('Unknown formatter: ' .. formatter)\n    end\n    return formatter\nend\n\n---Search upward from cwd for a binary inside a configurable directory using vim.fs.\n---@param search_root string The relative directory to search in (e.g., '.venv/bin', 'venv/bin')\n---@param binary_name string The binary name to search for (e.g., 'ipython', 'python3')\n---@param fallback_binary? string The fallback command to return if nothing is found\n---@return string The full path if found, otherwise the fallback command\nfunction M.cmd_builtin.find_binary(search_root, binary_name, fallback_binary)\n    local binary_path = vim.fs.joinpath(search_root, binary_name)\n\n    local paths = vim.fs.find(binary_path, {\n        upward = true,\n        type = 'file',\n    })\n\n    if #paths > 0 and vim.fn.executable(paths[1]) == 1 then\n        return paths[1]\n    end\n\n    return fallback_binary or binary_name\nend\n\nM.cmd_builtin['builtin:ipython'] = function()\n    local search_root = is_win32 and '.venv/Scripts' or '.venv/bin'\n    local binary = is_win32 and 'ipython.exe' or 'ipython'\n    return M.cmd_builtin.find_binary(search_root, binary, 'ipython')\nend\n\nM.cmd_builtin['builtin:python'] = function()\n    local search_root = is_win32 and '.venv/Scripts' or '.venv/bin'\n    local binary = is_win32 and 'python.exe' or 'python3'\n    local fallback_binary = is_win32 and 'python' or 'python3'\n    return M.cmd_builtin.find_binary(search_root, binary, fallback_binary)\nend\n\n---Resolve the cmd from either a string name or function\n---@param cmd string|string[]|function The cmd name, cmd list, or function\n---@return string|string[]|function The resolved cmd or function\nlocal function resolve_cmd(cmd)\n    if type(cmd) == 'string' and M.cmd_builtin[cmd] then\n        return M.cmd_builtin[cmd]\n    end\n    return cmd\nend\n\nfunction M.formatter.factory(opts)\n    if type(opts) ~= 'table' then\n        error 'opts must be a table'\n    end\n\n    local config = {\n        replace_tab_by_space = false,\n        number_of_spaces_to_replace_tab = 8,\n        when_multi_lines = {\n            open_code = '',\n            end_code = '\\r',\n            trim_empty_lines = false,\n            remove_leading_spaces = false,\n            -- If gsub_pattern and gsub_repl are not empty, `string.gsub` will\n            -- be called with `gsub_pattern` and `gsub_repl` on each line. Note\n            -- that you should use Lua pattern instead of Vim regex pattern.\n            -- The gsub calls happen after `trim_empty_lines`,\n            -- `remove_leading_spaces`, and `replace_tab_by_space`, and before\n            -- prepending and appending `open_code` and `end_code`.\n            gsub_pattern = '',\n            gsub_repl = '',\n        },\n        when_single_line = {\n            open_code = '',\n            end_code = '\\r',\n            gsub_pattern = '',\n            gsub_repl = '',\n        },\n        os = {\n            windows = {\n                join_lines_with_cr = true,\n            },\n        },\n    }\n\n    config = vim.tbl_deep_extend('force', config, opts)\n\n    return function(lines)\n        if #lines == 1 then\n            if config.replace_tab_by_space then\n                lines[1] = lines[1]:gsub('\\t', string.rep(' ', config.number_of_spaces_to_replace_tab))\n            end\n\n            lines[1] = lines[1]:gsub(config.when_single_line.gsub_pattern, config.when_single_line.gsub_repl)\n\n            lines[1] = config.when_single_line.open_code .. lines[1] .. config.when_single_line.end_code\n            return lines\n        end\n\n        local formatted_lines = {}\n        local line = lines[1]\n\n        line = line:gsub(config.when_multi_lines.gsub_pattern, config.when_multi_lines.gsub_repl)\n        line = config.when_multi_lines.open_code .. line\n\n        table.insert(formatted_lines, line)\n\n        for i = 2, #lines do\n            line = lines[i]\n\n            if config.when_multi_lines.trim_empty_lines and line == '' then\n                goto continue\n            end\n\n            if config.when_multi_lines.remove_leading_spaces then\n                line = line:gsub('^%s+', '')\n            end\n\n            if config.replace_tab_by_space then\n                line = line:gsub('\\t', string.rep(' ', config.number_of_spaces_to_replace_tab))\n            end\n\n            line = line:gsub(config.when_multi_lines.gsub_pattern, config.when_multi_lines.gsub_repl)\n\n            table.insert(formatted_lines, line)\n\n            ::continue::\n        end\n\n        if config.when_multi_lines.end_code then\n            table.insert(formatted_lines, config.when_multi_lines.end_code)\n        end\n\n        -- The `chansend` function joins lines with `\\n`, which can result in a\n        -- large number of unnecessary blank lines being sent to the REPL. For\n        -- example, `{ \"hello\", \"world\", \"again!\" }` would be sent to the REPL\n        -- as:\n\n        -- ```\n        -- hello\n        --\n        -- world\n        --\n        -- again!\n        -- ```\n\n        -- To prevent this issue, we manually join lines with `\\r` on Windows.\n        if is_win32 and config.os.windows.join_lines_with_cr then\n            formatted_lines = { table.concat(formatted_lines, '\\r') }\n        end\n\n        return formatted_lines\n    end\nend\n\nM.formatter.trim_empty_lines = M.formatter.factory {\n    when_multi_lines = {\n        trim_empty_lines = true,\n    },\n}\n\nM.formatter.bracketed_pasting = M.formatter.factory {\n    when_multi_lines = {\n        open_code = '\\27[200~',\n        end_code = '\\27[201~\\r',\n    },\n}\n\nM.formatter.bracketed_pasting_no_final_new_line = M.formatter.factory {\n    when_multi_lines = {\n        open_code = '\\27[200~',\n        end_code = '\\27[201~',\n    },\n}\n\n-- This formatter is only used with `send_delayed_final_cr` enabled, since the\n-- final cr is send via a delayed event, so we don't including the final new\n-- line in the code blocks we initially send to REPL.\nM.formatter.bracketed_pasting_delayed_cr = M.formatter.factory {\n    when_single_line = {\n        end_code = '',\n    },\n    when_multi_lines = {\n        open_code = '\\27[200~',\n        end_code = '\\27[201~',\n    },\n}\n\n--- Displays the source comment as virtual text in the REPL buffer.\n---@param repl table The REPL object.\n---@param original_content? string[] The original strings/code block sent by the user.\n---@param source_command? string The first line of the command sent to REPL, used for anchoring.\nlocal function show_source_command_hint(repl, original_content, source_command)\n    if not repl_is_valid(repl) then\n        return\n    end\n    if not source_command or source_command == '' then\n        return\n    end\n\n    source_command = source_command:match '^([^\\n]*)'\n\n    local meta = M._config.metas[repl.name]\n    local config = meta.source_command_hint\n\n    local code_part_for_display = ''\n    if original_content and #original_content > 0 then\n        for _, line_str in ipairs(original_content) do\n            local trimmed_line = vim.trim(line_str)\n            if #trimmed_line > 0 then\n                code_part_for_display = trimmed_line\n                break\n            end\n        end\n    end\n\n    if code_part_for_display == '' then\n        return\n    end\n\n    local comment_text = string.format(' %s - %s', os.date '%H:%M:%S', code_part_for_display)\n\n    local delay_ms = 400\n\n    vim.defer_fn(function()\n        if not repl_is_valid(repl) then\n            return\n        end\n\n        local buf = repl.bufnr\n        local lines = api.nvim_buf_get_lines(buf, 0, -1, false)\n        local matched_line\n\n        for i = #lines, 1, -1 do\n            if lines[i]:find(source_command, 1, true) then\n                matched_line = i - 1\n                break\n            end\n        end\n\n        if matched_line then\n            ---@diagnostic disable-next-line: need-check-nil\n            local hl_group = config.hl_group\n            local virt_lines_opts = {\n                virt_text = { { comment_text, hl_group } },\n                virt_text_pos = 'eol',\n            }\n            api.nvim_buf_set_extmark(buf, M._virt_text_ns_id, matched_line, 0, virt_lines_opts)\n        end\n    end, delay_ms)\nend\n\n---@param id number the id of the repl,\n---@param name string? the name of the closest repl that will try to find\n---@param bufnr number? the buffer number from which to find the attached REPL.\n---@param strings string[] a list of strings\n---@param use_formatter boolean? whether use formatter (e.g. bracketed_pasting)? Default: true\n---@param source_content boolean? Whether use source_syntax (defined by REPL meta) Default: false\n---@param send_delayed_final_cr boolean? Default: depends on REPL meta or config.os.windows.\n-- Send a list of strings to the repl specified by `id` and `name` and `bufnr`.\n-- If `id` is 0, then will try to find the REPL that `bufnr` is attached to. If\n-- a `name` is provided and that attached REPL matches it, the attached REPL is\n-- used. Otherwise it will use `id = 1`. If `name` is not nil or not an empty\n-- string, then will try to find the REPL with `name` relative to `id`. If\n-- `bufnr` is nil or `bufnr` = 0, will find the REPL that current buffer is\n-- attached to.\nM._send_strings = function(id, name, bufnr, strings, use_formatter, source_content, send_delayed_final_cr)\n    use_formatter = use_formatter == nil and true or use_formatter\n    if bufnr == nil or bufnr == 0 then\n        bufnr = api.nvim_get_current_buf()\n    end\n\n    local repl = M._get_repl(id, name, bufnr)\n\n    if not repl then\n        vim.notify [[REPL doesn't exist!]]\n        return\n    end\n\n    local meta = M._config.metas[repl.name]\n\n    if send_delayed_final_cr == nil then\n        if is_win32 and M._config.os.windows.send_delayed_final_cr then\n            send_delayed_final_cr = true\n        else\n            send_delayed_final_cr = meta.send_delayed_final_cr\n        end\n    end\n\n    if source_content then\n        local source_syntax = M.source_syntaxes[meta.source_syntax] or meta.source_syntax\n\n        if not source_syntax then\n            vim.notify(\n                'No source syntax or source function is available for '\n                    .. repl.name\n                    .. '. Fallback to send string directly.'\n            )\n        end\n\n        local content = table.concat(strings, '\\n')\n\n        local source_command_sent_to_repl\n\n        if type(source_syntax) == 'string' then\n            source_command_sent_to_repl = M.source_file_with_source_syntax(content, source_syntax)\n        elseif type(source_syntax) == 'function' then\n            source_command_sent_to_repl = source_syntax(content)\n        end\n\n        if source_command_sent_to_repl and source_command_sent_to_repl ~= '' then\n            if meta.source_command_hint.enabled then\n                show_source_command_hint(repl, strings, source_command_sent_to_repl)\n            end\n            strings = vim.split(source_command_sent_to_repl, '\\n')\n        end\n    else\n        strings = strings\n    end\n\n    if use_formatter then\n        strings = meta.formatter(strings)\n    end\n\n    fn.chansend(repl.term, strings)\n\n    -- See https://github.com/milanglacier/yarepl.nvim/issues/12 and\n    -- https://github.com/urbainvaes/vim-ripple/issues/12 for more information.\n    -- It may be necessary to use a delayed `<CR>` on Windows to ensure that\n    -- the code is executed in the REPL. Some REPLs also need this delayed CR\n    -- to recognize that we want to finalize/evaluate the command.\n    if send_delayed_final_cr then\n        vim.defer_fn(function()\n            if repl_is_valid(repl) then\n                fn.chansend(repl.term, '\\r')\n            end\n        end, 300)\n    end\n\n    if M._config.scroll_to_bottom_after_sending then\n        repl_win_scroll_to_bottom(repl)\n    end\nend\n\nM._send_operator_internal = function(motion)\n    -- hack: allow dot-repeat\n    if motion == nil then\n        vim.go.operatorfunc = [[v:lua.require'yarepl'._send_operator_internal]]\n        api.nvim_feedkeys('g@', 'ni', false)\n        return\n    end\n\n    local id = vim.b[0].repl_id\n    local name = vim.b[0].closest_repl_name\n    local current_bufnr = api.nvim_get_current_buf()\n\n    local lines = get_lines('operator', motion)\n\n    if #lines == 0 then\n        vim.notify 'No motion!'\n        return\n    end\n\n    M._send_strings(id, name, current_bufnr, lines)\n    if M._config.highlight_on_send_operator.enabled then\n        highlight_range(motion)\n    end\nend\n\nM._source_operator_internal = function(motion)\n    -- hack: allow dot-repeat\n    if motion == nil then\n        vim.go.operatorfunc = [[v:lua.require'yarepl'._source_operator_internal]]\n        api.nvim_feedkeys('g@', 'ni', false)\n        return\n    end\n\n    local id = vim.b[0].repl_id\n    local name = vim.b[0].closest_repl_name\n    local current_bufnr = api.nvim_get_current_buf()\n\n    local lines = get_lines('operator', motion)\n\n    if #lines == 0 then\n        vim.notify 'No motion!'\n        return\n    end\n\n    M._send_strings(id, name, current_bufnr, lines, nil, true)\n    if M._config.highlight_on_send_operator.enabled then\n        highlight_range(motion)\n    end\nend\n\nfunction M.run_cmd_with_count(cmd)\n    vim.cmd(string.format('%d%s', vim.v.count, cmd))\nend\n\nfunction M.partial_cmd_with_count_expr(cmd)\n    -- <C-U> is equivalent to \\21, we want to clear the range before\n    -- next input to ensure the count is recognized correctly.\n    return ':\\21' .. vim.v.count .. cmd\nend\n\nlocal function add_keymap(meta_name)\n    -- replace non alpha numeric and - _ keys to dash\n    if meta_name then\n        meta_name = meta_name:gsub('[^%w-_]', '-')\n    end\n\n    local suffix = meta_name and ('-' .. meta_name) or ''\n\n    local mode_commands = {\n        { 'n', 'REPLStart', 'start' },\n        { 'n', 'REPLStartOrFocusOrHide', 'start-or-focus-or-hide' },\n        { 'n', 'REPLFocus', 'focus' },\n        { 'n', 'REPLHide', 'hide' },\n        { 'n', 'REPLHideOrFocus', 'hide-or-focus' },\n        { 'n', 'REPLSendLine', 'send-line' },\n        { 'n', 'REPLSendOperator', 'send-operator' },\n        { 'v', 'REPLSendVisual', 'send-visual' },\n        { 'n', 'REPLSourceOperator', 'source-operator' },\n        { 'v', 'REPLSourceVisual', 'source-visual' },\n        { 'n', 'REPLClose', 'close' },\n    }\n\n    for _, spec in ipairs(mode_commands) do\n        api.nvim_set_keymap(spec[1], string.format('<Plug>(%s%s)', spec[2], suffix), '', {\n            noremap = true,\n            callback = function()\n                vim.deprecate(\n                    string.format('<Plug>(%s%s)', spec[2], suffix),\n                    string.format('<Plug>(yarepl-%s%s)', spec[3], suffix),\n                    '2026-06-01',\n                    'yarepl.nvim',\n                    false\n                )\n                if meta_name then\n                    M.run_cmd_with_count(spec[2] .. ' ' .. meta_name)\n                else\n                    M.run_cmd_with_count(spec[2])\n                end\n            end,\n        })\n    end\n\n    -- setting up keymaps for REPLExec is more complicated, setting it independently\n    api.nvim_set_keymap('n', string.format('<Plug>(%s%s)', 'REPLExec', suffix), '', {\n        noremap = true,\n        callback = function()\n            vim.deprecate(\n                string.format('<Plug>(REPLExec%s)', suffix),\n                string.format('<Plug>(yarepl-exec%s)', suffix),\n                '2026-06-01',\n                'yarepl.nvim',\n                false\n            )\n            if meta_name then\n                return M.partial_cmd_with_count_expr('REPLExec $' .. meta_name)\n            else\n                return M.partial_cmd_with_count_expr 'REPLExec '\n            end\n        end,\n        expr = true,\n    })\nend\n\nM.commands.start = function(opts)\n    local repl_name = opts.args\n    local current_bufnr = api.nvim_get_current_buf()\n\n    if repl_name == '' then\n        local id = opts.count == 0 and #M._repls + 1 or opts.count\n        local repl = M._repls[id]\n\n        if repl_is_valid(repl) then\n            vim.notify(string.format('REPL %d already exists', id))\n            focus_repl(repl)\n            return\n        end\n\n        local repls = {}\n        for name, _ in pairs(M._config.metas) do\n            table.insert(repls, name)\n        end\n\n        vim.ui.select(repls, {\n            prompt = 'Select REPL: ',\n        }, function(choice)\n            if not choice then\n                return\n            end\n\n            repl_name = choice\n            create_repl(id, repl_name)\n            post_create_repl(id, current_bufnr, opts)\n        end)\n    else\n        local id = #M._repls + 1\n\n        if opts.count ~= 0 then\n            local repl = find_repl_by_name_index(repl_name, opts.count)\n            if repl then\n                focus_repl(repl)\n                return\n            end\n        end\n\n        create_repl(id, repl_name)\n        post_create_repl(id, current_bufnr, opts)\n    end\nend\n\nM.commands.cleanup = repl_cleanup\n\nM.commands.focus = function(opts)\n    local id = opts.count\n    local name = opts.args\n    local current_buffer = api.nvim_get_current_buf()\n\n    local repl = M._get_repl(id, name, current_buffer)\n\n    if not repl then\n        vim.notify [[REPL doesn't exist!]]\n        return\n    end\n\n    focus_repl(repl)\nend\n\nM.commands.hide = function(opts)\n    local id = opts.count\n    local name = opts.args\n    local current_buffer = api.nvim_get_current_buf()\n\n    local repl = M._get_repl(id, name, current_buffer)\n\n    if not repl then\n        vim.notify [[REPL doesn't exist!]]\n        return\n    end\n\n    local bufnr = repl.bufnr\n    local win = fn.bufwinid(bufnr)\n    while win ~= -1 do\n        api.nvim_win_close(win, true)\n        win = fn.bufwinid(bufnr)\n    end\nend\n\nlocal function hide_or_focus_repl(repl)\n    if not repl_is_valid(repl) then\n        vim.notify [[REPL doesn't exist!]]\n        return\n    end\n\n    local bufnr = repl.bufnr\n    local win = fn.bufwinid(bufnr)\n    if win ~= -1 then\n        while win ~= -1 do\n            api.nvim_win_close(win, true)\n            win = fn.bufwinid(bufnr)\n        end\n    else\n        focus_repl(repl)\n    end\nend\n\nM.commands.hide_or_focus = function(opts)\n    local id = opts.count\n    local name = opts.args\n    local current_buffer = api.nvim_get_current_buf()\n\n    local repl = M._get_repl(id, name, current_buffer)\n\n    if not repl then\n        vim.notify [[REPL doesn't exist!]]\n        return\n    end\n\n    hide_or_focus_repl(repl)\nend\n\nM.commands.start_or_focus_or_hide = function(opts)\n    local id = opts.count\n    local name = opts.args\n    local has_name = name ~= nil and name ~= ''\n    local repl\n\n    if id == 0 then\n        if has_name then\n            repl = find_repl_by_name_index(name, 1)\n        else\n            repl = M._repls[1]\n        end\n\n        if repl_is_valid(repl) then\n            hide_or_focus_repl(repl)\n            return\n        end\n    else\n        if has_name then\n            repl = find_repl_by_name_index(name, id)\n        else\n            repl = M._repls[id]\n        end\n        if repl_is_valid(repl) then\n            hide_or_focus_repl(repl)\n            return\n        end\n    end\n\n    M.commands.start(opts)\nend\n\nM.commands.close = function(opts)\n    local id = opts.count\n    local name = opts.args\n    local current_buffer = api.nvim_get_current_buf()\n\n    local repl = M._get_repl(id, name, current_buffer)\n\n    if not repl then\n        vim.notify [[REPL doesn't exist!]]\n        return\n    end\n\n    fn.chansend(repl.term, string.char(4))\nend\n\nM.commands.swap = function(opts)\n    local id_1 = tonumber(opts.fargs[1])\n    local id_2 = tonumber(opts.fargs[2])\n\n    if id_1 ~= nil and id_2 ~= nil then\n        repl_swap(id_1, id_2)\n        return\n    end\n\n    local repl_ids = {}\n    for id, _ in pairs(M._repls) do\n        table.insert(repl_ids, id)\n    end\n\n    table.sort(repl_ids)\n\n    if id_1 == nil then\n        vim.ui.select(repl_ids, {\n            prompt = 'select first REPL',\n            format_item = function(item)\n                return item .. ' ' .. M._repls[item].name\n            end,\n        }, function(id1)\n            if not id1 then\n                return\n            end\n\n            vim.ui.select(repl_ids, {\n                prompt = 'select second REPL',\n                format_item = function(item)\n                    return item .. ' ' .. M._repls[item].name\n                end,\n            }, function(id2)\n                if not id2 then\n                    return\n                end\n\n                repl_swap(id1, id2)\n            end)\n        end)\n    elseif id_2 == nil then\n        vim.ui.select(repl_ids, {\n            prompt = 'select second REPL',\n            format_item = function(item)\n                return item .. ' ' .. M._repls[item].name\n            end,\n        }, function(id2)\n            if not id2 then\n                return\n            end\n\n            repl_swap(id_1, id2)\n        end)\n    end\nend\n\nM.commands.attach_buffer = function(opts)\n    local current_buffer = api.nvim_get_current_buf()\n\n    if opts.bang then\n        M._bufnrs_to_repls[current_buffer] = nil\n        return\n    end\n\n    local repl_id = opts.count\n\n    local repl_ids = {}\n    for id, _ in pairs(M._repls) do\n        table.insert(repl_ids, id)\n    end\n\n    -- count = 0 means no count is provided\n    if repl_id == 0 then\n        vim.ui.select(repl_ids, {\n            prompt = 'select REPL that you want to attach to',\n            format_item = function(item)\n                return item .. ' ' .. M._repls[item].name\n            end,\n        }, function(id)\n            if not id then\n                return\n            end\n            attach_buffer_to_repl(current_buffer, M._repls[id])\n        end)\n    else\n        attach_buffer_to_repl(current_buffer, M._repls[repl_id])\n    end\nend\n\nM.commands.detach_buffer = function()\n    local current_buffer = api.nvim_get_current_buf()\n    M._bufnrs_to_repls[current_buffer] = nil\nend\n\nM.commands.send_visual = function(opts)\n    local id = opts.count\n    local name = opts.args\n    local current_buffer = api.nvim_get_current_buf()\n\n    api.nvim_feedkeys('\\27', 'nx', false)\n\n    local visual_mode = vim.fn.visualmode()\n    local lines = get_lines('visual', visual_mode)\n\n    if #lines == 0 then\n        vim.notify 'No visual range!'\n        return\n    end\n\n    M._send_strings(id, name, current_buffer, lines, nil, opts.source_content)\nend\n\nM.commands.send_line = function(opts)\n    local id = opts.count\n    local name = opts.args\n    local current_buffer = api.nvim_get_current_buf()\n\n    local line = api.nvim_get_current_line()\n\n    M._send_strings(id, name, current_buffer, { line })\nend\n\nM.commands.send_operator = function(opts)\n    local repl_name = opts.args\n    local id = opts.count\n\n    if repl_name ~= '' then\n        vim.b[0].closest_repl_name = repl_name\n    else\n        vim.b[0].closest_repl_name = nil\n    end\n\n    if id ~= 0 then\n        vim.b[0].repl_id = id\n    else\n        vim.b[0].repl_id = nil\n    end\n\n    vim.go.operatorfunc = opts.source_content and [[v:lua.require'yarepl'._source_operator_internal]]\n        or [[v:lua.require'yarepl'._send_operator_internal]]\n    api.nvim_feedkeys('g@', 'ni', false)\nend\n\nM.commands.source_visual = function(opts)\n    opts.source_content = true\n    M.commands.send_visual(opts)\nend\n\nM.commands.source_operator = function(opts)\n    opts.source_content = true\n    M.commands.send_operator(opts)\nend\n\nM.commands.exec = function(opts)\n    local first_arg = opts.fargs[1]\n    local current_buffer = api.nvim_get_current_buf()\n    local name = ''\n    local command = opts.args\n\n    for repl_name, _ in pairs(M._config.metas) do\n        if '$' .. repl_name == first_arg then\n            name = first_arg:sub(2)\n            break\n        end\n    end\n\n    if name ~= '' then\n        command = command:gsub('^%$' .. name .. '%s+', '')\n    end\n\n    local id = opts.count\n    local command_list = vim.split(command, '\\r')\n\n    M._send_strings(id, name, current_buffer, command_list)\nend\n\n---@param content string\n---@param keep_file boolean? Whether keep the temporary file after temporary execution\n---@return string? The file name of the temporary file\nfunction M.make_tmp_file(content, keep_file)\n    local tmp_file = os.tmpname() .. '_yarepl'\n\n    local f = io.open(tmp_file, 'w+')\n    if f == nil then\n        M.notify('Cannot open temporary message file: ' .. tmp_file, 'error', vim.log.levels.ERROR)\n        return\n    end\n\n    f:write(content)\n    f:close()\n\n    if not keep_file then\n        vim.defer_fn(function()\n            os.remove(tmp_file)\n        end, 5000)\n    end\n\n    return tmp_file\nend\n\n---@param content string\n---@param source_syntax string\n---@param keep_file boolean?\n---@reutrn string? The syntax to source the file\nfunction M.source_file_with_source_syntax(content, source_syntax, keep_file)\n    local tmp_file = os.tmpname() .. '_yarepl'\n\n    local f = io.open(tmp_file, 'w+')\n    if f == nil then\n        M.notify('Cannot open temporary message file: ' .. tmp_file, 'error', vim.log.levels.ERROR)\n        return\n    end\n\n    f:write(content)\n    f:close()\n\n    if not keep_file then\n        vim.defer_fn(function()\n            os.remove(tmp_file)\n        end, 5000)\n    end\n\n    -- replace {{file}} placeholder with the temp file name\n    source_syntax = source_syntax:gsub('{{file}}', tmp_file)\n\n    return source_syntax\nend\n\n---@type table<string, string | fun(str: string): string?>\nM.source_syntaxes = {}\n\nM.source_syntaxes.python = function(str)\n    -- Preserve the temporary file since PDB requires its existence for\n    -- displaying context via the `list` command\n    return M.source_file_with_source_syntax(\n        str,\n        'exec(compile(open(\"{{file}}\", \"r\").read(), \"{{file}}\", \"exec\"))',\n        true\n    )\nend\n\nM.source_syntaxes.ipython = function(str)\n    -- The `-i` flag ensures the current environment is inherited when\n    -- executing the file\n    return M.source_file_with_source_syntax(str, '%run -i \"{{file}}\"', true)\nend\n\nM.source_syntaxes.bash = 'source \"{{file}}\"'\nM.source_syntaxes.R = 'eval(parse(text = readr::read_file(\"{{file}}\")))'\nM.source_syntaxes.aichat = '.file \"{{file}}\"'\n\n-- New <Plug>(yarepl-*) keymaps\n\nlocal function add_yarepl_keymap(meta_name)\n    if meta_name then\n        meta_name = meta_name:gsub('[^%w-_]', '-')\n    end\n\n    local suffix = meta_name and ('-' .. meta_name) or ''\n\n    local mode_commands = {\n        { 'n', 'start' },\n        { 'n', 'start_or_focus_or_hide' },\n        { 'n', 'focus' },\n        { 'n', 'hide' },\n        { 'n', 'hide_or_focus' },\n        { 'n', 'send_line' },\n        { 'n', 'send_operator' },\n        { 'v', 'send_visual' },\n        { 'n', 'source_operator' },\n        { 'v', 'source_visual' },\n        { 'n', 'close' },\n    }\n\n    for _, spec in ipairs(mode_commands) do\n        local plug_name = spec[2]:gsub('_', '-')\n        api.nvim_set_keymap(spec[1], string.format('<Plug>(yarepl-%s%s)', plug_name, suffix), '', {\n            noremap = true,\n            callback = function()\n                if meta_name then\n                    M.run_cmd_with_count('Yarepl ' .. spec[2] .. ' ' .. meta_name)\n                else\n                    M.run_cmd_with_count('Yarepl ' .. spec[2])\n                end\n            end,\n        })\n    end\n\n    api.nvim_set_keymap('n', string.format('<Plug>(yarepl-exec%s)', suffix), '', {\n        noremap = true,\n        callback = function()\n            if meta_name then\n                return M.partial_cmd_with_count_expr('Yarepl exec $' .. meta_name)\n            else\n                return M.partial_cmd_with_count_expr 'Yarepl exec '\n            end\n        end,\n        expr = true,\n    })\nend\n\nM._add_yarepl_keymap = add_yarepl_keymap\n\nM.setup = function(opts)\n    M._config = vim.tbl_deep_extend('force', default_config(), opts or {})\n\n    -- Check for deprecated option\n    if opts and opts.os and opts.os.windows and opts.os.windows.send_delayed_cr_after_sending ~= nil then\n        vim.deprecate(\n            'os.windows.send_delayed_cr_after_sending',\n            'os.windows.send_delayed_final_cr',\n            '2026-06-01',\n            'yarepl.nvim',\n            false\n        )\n\n        M._config.os.windows.send_delayed_final_cr = opts.os.windows.send_delayed_cr_after_sending\n    end\n\n    for name, meta in pairs(M._config.metas) do\n        -- remove the disabled builtin meta passed from user config\n        if not meta then\n            M._config.metas[name] = nil\n        else\n            -- Convert string formatter names to actual formatter functions\n            if meta.formatter then\n                meta.formatter = get_formatter(meta.formatter)\n            end\n\n            -- Resolve string cmd names to builtin cmd functions\n            if meta.cmd then\n                meta.cmd = resolve_cmd(meta.cmd)\n            end\n\n            meta.source_command_hint =\n                vim.tbl_deep_extend('force', M._config.source_command_hint, meta.source_command_hint or {})\n        end\n    end\n\n    add_keymap()\n    add_yarepl_keymap()\n\n    for meta_name, _ in pairs(M._config.metas) do\n        add_keymap(meta_name)\n        add_yarepl_keymap(meta_name)\n    end\nend\n\nlocal function list_metas()\n    local metas = {}\n    for name, _ in pairs(M._config.metas) do\n        table.insert(metas, name)\n    end\n    return metas\nend\n\nlocal function deprecate_command(old, new)\n    return function(opts)\n        vim.deprecate(old, 'Yarepl ' .. new, '2026-06-01', 'yarepl.nvim', false)\n        M.commands[new](opts)\n    end\nend\n\napi.nvim_create_user_command('REPLStart', deprecate_command('REPLStart', 'start'), {\n    count = true,\n    bang = true,\n    nargs = '?',\n    complete = list_metas,\n    desc = [[\nCreate REPL `i` from the list of available REPLs.\n]],\n})\n\napi.nvim_create_user_command(\n    'REPLStartOrFocusOrHide',\n    deprecate_command('REPLStartOrFocusOrHide', 'start_or_focus_or_hide'),\n    {\n        count = true,\n        bang = true,\n        nargs = '?',\n        complete = list_metas,\n        desc = [[\nStart a REPL or toggle focus/hide on an existing REPL.\n]],\n    }\n)\n\napi.nvim_create_user_command(\n    'REPLCleanup',\n    deprecate_command('REPLCleanup', 'cleanup'),\n    { desc = 'clean invalid repls, and rearrange the repls order.' }\n)\n\napi.nvim_create_user_command('REPLFocus', deprecate_command('REPLFocus', 'focus'), {\n    count = true,\n    nargs = '?',\n    desc = [[\nFocus on REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\napi.nvim_create_user_command('REPLHide', deprecate_command('REPLHide', 'hide'), {\n    count = true,\n    nargs = '?',\n    desc = [[\nHide REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\napi.nvim_create_user_command('REPLHideOrFocus', deprecate_command('REPLHideOrFocus', 'hide_or_focus'), {\n    count = true,\n    nargs = '?',\n    desc = [[\nHide or focus REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\napi.nvim_create_user_command('REPLClose', deprecate_command('REPLClose', 'close'), {\n    count = true,\n    nargs = '?',\n    desc = [[\nClose REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\napi.nvim_create_user_command('REPLSwap', deprecate_command('REPLSwap', 'swap'), {\n    desc = [[Swap two REPLs]],\n    nargs = '*',\n})\n\napi.nvim_create_user_command('REPLAttachBufferToREPL', deprecate_command('REPLAttachBufferToREPL', 'attach_buffer'), {\n    count = true,\n    bang = true,\n    desc = [[\nAttach current buffer to REPL `i`\n]],\n})\n\napi.nvim_create_user_command('REPLDetachBufferToREPL', deprecate_command('REPLDetachBufferToREPL', 'detach_buffer'), {\n    count = true,\n    desc = [[Detach current buffer to any REPL.]],\n})\n\napi.nvim_create_user_command('REPLSendVisual', deprecate_command('REPLSendVisual', 'send_visual'), {\n    count = true,\n    nargs = '?',\n    desc = [[\nSend visual range to REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\napi.nvim_create_user_command('REPLSendLine', deprecate_command('REPLSendLine', 'send_line'), {\n    count = true,\n    nargs = '?',\n    desc = [[\nSend current line to REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\napi.nvim_create_user_command('REPLSendOperator', deprecate_command('REPLSendOperator', 'send_operator'), {\n    count = true,\n    nargs = '?',\n    desc = [[\nThe operator of send text to REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\napi.nvim_create_user_command('REPLSourceVisual', deprecate_command('REPLSourceVisual', 'source_visual'), {\n    count = true,\n    nargs = '?',\n    desc = [[\nSource visual range to REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\napi.nvim_create_user_command('REPLSourceOperator', deprecate_command('REPLSourceOperator', 'source_operator'), {\n    count = true,\n    nargs = '?',\n    desc = [[\nSource visual range to REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\napi.nvim_create_user_command('REPLExec', deprecate_command('REPLExec', 'exec'), {\n    count = true,\n    nargs = '*',\n    desc = [[\nExecute a command in REPL `i` or the REPL that current buffer is attached to.\n]],\n})\n\n-- Unified Yarepl command\n\nM.completions = {\n    start = list_metas,\n    start_or_focus_or_hide = list_metas,\n    cleanup = true,\n    focus = list_metas,\n    hide = list_metas,\n    hide_or_focus = list_metas,\n    close = list_metas,\n    swap = true,\n    attach_buffer = true,\n    detach_buffer = true,\n    send_visual = list_metas,\n    send_line = list_metas,\n    send_operator = list_metas,\n    source_visual = list_metas,\n    source_operator = list_metas,\n    exec = true,\n}\n\nlocal function yarepl_complete(arglead, cmdline, _)\n    cmdline = cmdline or ''\n    local parts = vim.split(vim.trim(cmdline), '%s+')\n\n    ---@type table|function\n    local node = M.completions\n\n    local n_fully_typed_parts = #parts\n    if arglead ~= '' and #parts > 0 then\n        n_fully_typed_parts = n_fully_typed_parts - 1\n    end\n\n    for i = 2, n_fully_typed_parts do\n        local part = parts[i]\n        if type(node) ~= 'table' or node[part] == nil then\n            return {}\n        end\n        node = node[part]\n    end\n\n    if type(node) == 'function' then\n        return vim.tbl_filter(function(item)\n            return vim.startswith(item, arglead)\n        end, node())\n    elseif type(node) == 'table' then\n        return vim.tbl_filter(function(item)\n            return vim.startswith(item, arglead)\n        end, vim.tbl_keys(node))\n    end\n\n    return {}\nend\n\napi.nvim_create_user_command('Yarepl', function(opts)\n    local fargs = opts.fargs\n    if #fargs == 0 then\n        vim.notify('Yarepl: subcommand required', vim.log.levels.ERROR)\n        return\n    end\n\n    local subcmd = table.remove(fargs, 1)\n\n    local handler = M.commands[subcmd]\n    if type(handler) ~= 'function' then\n        vim.notify('Yarepl: unknown subcommand: ' .. subcmd, vim.log.levels.ERROR)\n        return\n    end\n\n    -- Reconstruct the args string (everything after the subcommand)\n    local args = table.concat(fargs, ' ')\n\n    handler {\n        args = args,\n        fargs = fargs,\n        count = opts.count,\n        bang = opts.bang,\n    }\nend, {\n    count = true,\n    bang = true,\n    nargs = '+',\n    complete = yarepl_complete,\n    desc = 'Unified yarepl command. Usage: Yarepl <subcommand> [args]',\n})\n\nreturn M\n"
  },
  {
    "path": "neovim.toml",
    "content": "[selene]\nbase = \"lua51\"\nname = \"neovim\"\n\n[vim]\nany = true\n\n[[assert.args]]\ntype = \"bool\"\n\n[[assert.args]]\ntype = \"string\"\nrequired = false\n\n[[after_each.args]]\ntype = \"function\"\n\n[[before_each.args]]\ntype = \"function\"\n\n[[describe.args]]\ntype = \"string\"\n\n[[describe.args]]\ntype = \"function\"\n\n[[it.args]]\ntype = \"string\"\n\n[[it.args]]\ntype = \"function\"\n"
  },
  {
    "path": "selene.toml",
    "content": "std = \"neovim\"\n\n[rules]\nglobal_usage = \"allow\"\nmultiple_statements = \"allow\"\n"
  }
]