{"id":13479637,"url":"https://github.com/ubaldot/vim-replica","last_synced_at":"2025-03-17T11:30:49.012Z","repository":{"id":153838146,"uuid":"621525297","full_name":"ubaldot/vim-replica","owner":"ubaldot","description":"Enjoy Jupyter through Vim!","archived":false,"fork":false,"pushed_at":"2025-02-18T14:34:06.000Z","size":4970,"stargazers_count":28,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-16T11:21:57.783Z","etag":null,"topics":["jupyter","python","repl","vim","vim9"],"latest_commit_sha":null,"homepage":"https://www.vim.org/scripts/script.php?script_id=6067","language":"Vim Script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ubaldot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-30T20:56:40.000Z","updated_at":"2025-03-01T11:00:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"278f74d3-3609-4932-aa62-25b258614dc7","html_url":"https://github.com/ubaldot/vim-replica","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubaldot%2Fvim-replica","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubaldot%2Fvim-replica/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubaldot%2Fvim-replica/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubaldot%2Fvim-replica/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ubaldot","download_url":"https://codeload.github.com/ubaldot/vim-replica/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244025242,"owners_count":20385540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jupyter","python","repl","vim","vim9"],"created_at":"2024-07-31T16:02:20.612Z","updated_at":"2025-03-17T11:30:48.181Z","avatar_url":"https://github.com/ubaldot.png","language":"Vim Script","funding_links":[],"categories":["Vim Script","Integrations"],"sub_categories":[],"readme":"# **REPL**ica.vim\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"/ReplicaDemo.gif\" width=\"75%\" height=\"75%\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\" style=\"font-size:38;\"\u003e\n* Enjoy Jupyter through Vim! *\n\u003c/p\u003e\n\n## Introduction\n\nReplica allows REPL shells such as IPython or Julia inside Vim in a seamless\nway.\n\nIt supports the following key features:\n\n1. Send lines, files and code-cells to a REPL,\n2. Highlight code-cells.\n\nI wrote vim-replica because I always had problems with\n[vim-slime](https://github.com/jpalardy/vim-slime) under Windows and\n[vim-REPL](https://github.com/sillybun/vim-repl) crashes too often when using\nthe toggle function and I discovered\n[jupyter-vim](https://github.com/jupyter-vim/jupyter-vim) too late.\n\nIf you like this plugin you may also want to take a look at\n[vim-outline](https://github.com/ubaldot/vim-outline).\n\n## Requirements\n\nReplica is entirely written in _Vim9script_, hence you need at least Vim 9.0\ncompiled with `python3` support.\n\nYou also need [jupyter console](https://github.com/jupyter/jupyter_console)\nand the [kernels](https://github.com/jupyter/jupyter/wiki/Jupyter-kernels) of\nthe languages you would like to use.\u003cbr\u003e\u003cbr\u003e That is pretty much all.\n\n## Usage\n\n#### Commands\n\n`:ReplicaConsoleToggle` - un-hide and hide the REPL.\n\n`:ReplicaConsoleRestart` - restart the REPL.\n\n`:ReplicaConsoleShutoff` - wipeout the buffer associated to the REPL.\n\n`:[range]ReplicaSendLines` - send the lines in _[range]_ to the REPL.\n\n`:ReplicaSendCell` - send the current code-cell.\n\n`:ReplicaSendFile [{file}]` - send {file} to the REPL. If no file is given,\nsend the content of the current buffer.\n\n`:ReplicaRemoveCells` - remove all the cells from the current buffer.\n\n#### Mappings\n\nBy setting `g:replica_use_default_mapping = true` you will get the following\nmappings.\n\n```\n# Default mappings\nnmap \u003cF2\u003e \u003cPlug\u003eReplicaConsoleToggle\u003ccr\u003e\n\nnmap \u003cF9\u003e \u003cPlug\u003eReplicaSendLines\u003ccr\u003e\nxmap \u003cF9\u003e \u003cPlug\u003eReplicaSendLines\u003ccr\u003e\n\nnmap \u003cF5\u003e \u003cPlug\u003eReplicaSendFile\u003ccr\u003e\n\nnmap \u003cc-enter\u003e \u003cPlug\u003eReplicaSendCell\u003ccr\u003ej\n```\n\n\u003e **Warning**\n\u003e\n\u003e Both the above commands and mappings work if they are run from a buffer\n\u003e whose _filetype_ is supported.\n\n## Basic Configuration\n\n```\n# Default values\ng:replica_display_range = false\ng:replica_enable_highlight = true\ng:replica_console_position = \"L\"\ng:replica_console_height = \u0026lines\ng:replica_console_width = floor(\u0026columns/2)\ng:replica_kernels = {python: \"python3\",\n                   julia: \"julia-1.8\"}\ng:replica_cells_delimiters = { python: \"# %%\",\n                             julia: \"# %%\"}\ng:replica_jupyter_console_options = {\n                    python: \"\",\n                    julia: \"\"}\n```\n\n## Adding new languages\n\nAt the moment Replica support _python_ and _julia_ but adding new languages\nshould not be too difficult.\u003cbr\u003e\n\nSay that you want to add `foo` language to Replica. You proceed in two steps:\n\n1. Add a new key-value pair to the `g:replica_kernels`, `g:replica_names`,\n   `g:replica_jupyter_console_options`, `g:replica_cells_delimiters` and\n   `g:replica_run_commands` dictionaries. Take a look at `:h replica.txt` to\n   understand how to set them.\n2. Duplicate any existing file in `vim-replica/ftplugin/` file and rename it\n   as `foo.vim`. Note that `foo` must be a recognized vim _filetype_.\n\nDone!\u003cbr\u003e Your new language is now added to vim-replica! If you add a new\nlanguage consider to issue a PR.\n\n\u003e **Note**\n\u003e\n\u003e You could also use the global `ftplugin` folder instead of the plugin\n\u003e `vim-replica/ftplugin` folder but that has not been tested yet.\n\n## Troubleshooting\n\n#### Q: The REPL does not even start!\n\nA: Ok, let's start with some basic checks:\n\n1. run `:echo has('python3')`. The answer should be `1`.\n2. if you are using Windows, make sure that Python and Vim are both 32- or 64\n   bit.\n\nNext, be sure that in the current virtual environment:\n\n1. `jupyter console` is installed,\n2. some `ipython` jupyter kernel (e.g. `pyhon3`) is installed,\n3. vim is launched from this virtual environment.\n\n#### Q: When I open the REPL the layout is horrible!\n\nA: Set a desired value of `g:replica_console_height` and\n`g:replica_console_width` in your `vimrc`.\u003cbr\u003e The units are number of lines\nand number of columns, respectively. \u003cbr\u003e\n\n#### Q. Vim slow down a lot with this st\"pid plugin!\n\nA: You can try to set `g:replica_alt_highlight = true` in your _vimrc_.\u003cbr\u003e\nOr, if still slow, you can try to disable the cells highlighting by setting\n`g:replica_enable_highlight` to `false`.\n\n#### Q. I am using matplotlib and the figures are not interactive.\n\nA: This is more a matplotlib setting than a replica problem. :) You should\nchange the matplotlib backend. For example, you could use the magic\n`%matplotlib qt` to use the `qt` backend. See matplotlib docs for more info.\n\n#### Q. Is it possible to embed figures in the console?\n\nA: I am not a fan of inline figures, so I haven't tested but I will try to\ngive you an answer anyway. In general, you cannot display pictures in terminal\nemulators, but there are some that allows you to do that (I think kitty is one\nbut there should be others out there). Hence, to display inline figures I\nthink that you need (but I may be wrong) the following:\n\n1.  A terminal emulator that support images display,\n2.  A library that allows inline figures.\n\nAgain, I prefer floating, interactive figure, but it you succeed in displaying\ninline figures while using Replica, out of curiosity, please let us know. :)\n\n#### Q. When I call `:ReplicaConsoleToggle` the console window won't close.\n\nA: Replica commands work if executed from a buffer with a supported\n_filetype_. \u003cbr\u003e That is, if you have an _IPYTHON_ console displayed in a\nwindow and you call `:ReplicaConsoleToggle` from a `text` _filetype_ buffer,\nthen nothing will happen. This because if you have a Python and a Julia\nconsole open and you are editing a .txt file, then which console should close?\nPython? Julia? Both? At the moment, you can close the window where the console\nis running with standard Vim commands such as `\u003cc-w\u003eq`, `:close`, `:$close`,\netc. Such a behavior may change if there is a sufficiently large amount of\nusers who wants that. :)\n\n#### Q. Is it possible to copy from the REPL to a buffer?\n\nA: Yes! If you `\u003cc-w\u003eN` in your REPL, then it becomes an ordinary buffer.\u003cbr\u003e\nThere you can yank everything you want.\u003cbr\u003e To re-enable the REPL press `i`\nwith the cursor located on the REPL window.\n\n#### Q. How do I know which kernel is running on a given console?\n\nA: Go on the open console, hit `\u003cc-w\u003e` and type `:echo b:kernel_name`.\n\n#### Q. Is it possible to automatically change the REPL folder when I change\n\n#### Vim folder?\n\nA: Yes, but you need to define your own function, something like the\nfollowing:\n\n```\ndef ChangeTerminalDir()\n    for ii in term_list()\n        if bufname(ii) == \"JULIA\"\n           term_sendkeys(ii, $'cd {getcwd()}\\n\")\n        else\n           term_sendkeys(ii, $'cd {getcwd()}\\n')\n        endif\n    endfor\nenddef\n\naugroup DIRCHANGE\n    au!\n    autocmd DirChanged global ChangeTerminalDir()\naugroup END\n```\n\n\u003e **Note**\n\u003e\n\u003e The above function is an example and it has its own limitations. For\n\u003e example, it does not work the other way around, i.e. if you change folder\n\u003e from a _terminal_ buffer then the Vim current folder won't change.\n\n## Contributing\n\nContributions are more than welcome!\u003cbr\u003e In the source code there are TODO\nitems. Feel free to address any of them or propose your own change.\n\n## Help\n\nThis README is a good start to get some insights on Replica, but you can find\nmore info in `:h replica.txt`.\n\n## License\n\nBSD3-Clause.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fubaldot%2Fvim-replica","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fubaldot%2Fvim-replica","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fubaldot%2Fvim-replica/lists"}