Replica integrates with the following REPL programs:
- IPython
- Julia
- R
- sh
- zsh
- PowerShell
Additional REPL can be easily included. See :h ReplicaContributing.
I wrote vim-replica because I always had problems with vim-slime under Windows and vim-REPL crashes too often when using the toggle function.
If you like this plugin you may also want to take a look at vim-outline.
Replica is entirely written in Vim9script, hence you need at least Vim 9.0
compiled with python3 support.
:ReplicaConsoleToggle # Un-hide and hide the REPL
:[range]ReplicaSendLines # Send the lines in [range] to the REPL
:ReplicaSendCell # Send the current code cell
:ReplicaSendFile [{file}] # Send {file} to the REPL. If no file is given, it send the current buffer
:ReplicaRemoveCells # Remove all the cells from the current buffer
:ReplicaInspect [{variable}] # Display {variable}. If no argument is given, display all variables
# in the current session. <tab> completion available.
:ReplicaConsoleRestart # Restart the REPL
:ReplicaConsoleShutoff # Wipeout the buffer associated to the REPLBy setting g:replica_config.use_default_mapping = true you will get the
following mappings:
# Default mappings
nmap <F2> <Plug>ReplicaConsoleToggle<cr>
nmap <F9> <Plug>ReplicaSendLines<cr>
xmap <F9> <Plug>ReplicaSendLines<cr>
nmap <F5> <Plug>ReplicaSendFile<cr>
nmap <c-enter> <Plug>ReplicaSendCell<cr>j# Example
g:replica_config = {}
g:replica_config['console_position'] = "L"
g:replica_config['display_range'] = true
g:replica_config['enable_highlight'] = true
g:replica_config['alt_highlight'] = false
g:replica_config['use_default_mapping'] = false
g:replica_config['display_variables'] = 'tab'
g:replica_config['repl_options'] = {
python: "",
julia: "",
r: "",
sh: "",
zsh: "",
ps1: ""}At the moment Replica supports python, julia, R, sh, zsh and ps1 but adding new languages should not be too difficult.
Say that you want to add foo language to Replica. You proceed in two steps:
- Edit
plugin/replica.vimand add a new key-value pair to the internal dictionaries. Take a look at:h replica.txtfor details on what each entry should contain. - If the new REPL requires extra start-up options, add a corresponding entry
to
g:replica_config.repl_optionsin yourvimrc.
Done!
Your new language is now added to vim-replica! If you add a new language consider to issue a PR.
Ok, let's start with some basic checks:
- Make sure the REPL executable is in your
$PATH(e.g.ipython,julia,Rscript,bash,zsh,pwsh). - If you are using Python, make sure the virtual environment is active and
ipythonis installed in it, then launch Vim from that environment. - Run
:echo has('terminal')— the answer must be1.
Set a desired value of g:replica_config.console_height and
g:replica_config.console_width in your vimrc.
The units are number of lines and number of columns, respectively.
You can try to set g:replica_config.alt_highlight = true in your vimrc.
Or, if still slow, you can try to disable the cells highlighting by setting
g:replica_config.enable_highlight to false.
This is more a matplotlib setting than a replica problem. :)
You should change the matplotlib backend. For example, you could use the magic
%matplotlib qt to use the qt backend. See matplotlib docs for more info.
You can switch how you want to explore your variables through
g:replica_config.display_variables. Possible choices are split, vsplit,
tab and popup.
Replica commands work if executed from a buffer with a supported filetype.
That is, if you have an IPYTHON console displayed in a
window and you call :ReplicaConsoleToggle from a text filetype buffer,
then nothing will happen.
This because if you have a Python and a Julia console open and you are editing a .txt file, then which console should close? Python? Julia? Both?
At the moment, you can close the window where the console
is running with standard Vim commands such as <c-w>q, :close, :$close,
etc. Such a behavior may change if there is a sufficiently large amount of
users who wants that. :)
Yes! If you <c-w>N in your REPL, then it becomes an ordinary buffer.
There you can yank everything you want.
To re-enable the REPL press i with the cursor located on the REPL window.
Yes, but you need to define your own function, something like the following:
def ChangeTerminalDir()
for ii in term_list()
if bufname(ii) == "JULIA"
term_sendkeys(ii, $'cd {getcwd()}\n")
else
term_sendkeys(ii, $'cd {getcwd()}\n')
endif
endfor
enddef
augroup DIRCHANGE
au!
autocmd DirChanged global ChangeTerminalDir()
augroup END
Note
The above function is an example and it has its own limitations. For example, it does not work the other way around, i.e. if you change folder from a terminal buffer then the Vim current folder won't change.
This README is a good start to get some insights on Replica, but you can find
more info in :h replica.txt.
BSD3-Clause.