Vim provides a ":terminal" command, which opens up a terminal window inside the editor. This can be useful to directly copy-paste snippets of code between an active REPL and your editor window.
For example, I have Scheme48 installed, with its home directory on the path. I can open a Scheme 48 REPL inside Vim using:
:term scheme48.bat
This opens the window above the current one - to open the window to the side, use:
:vert :term scheme48.bat
This places the cursor in the REPL, and you can evaluate simple expressions:
To exit the terminal, type CTRL-W N to enter normal mode, then :q!
Let's type a simple expression into the text window and execute it in the terminal:
- Type CTRL-W CTRL-W to switch to the text window
-
Type
(+ 4 3)
- ESC-yy to yank the expression into the unnamed register
- CTRL-W CTRL-W to switch to the Scheme 48 REPL
- CTRL-W " " to paste the unnamed register contents into the REPL
- You may need to press ENTER to evaluate the expression
You can use Vim's registers to hold different test expressions, or use the REPL history to repeat test expressions while redefining functions.
In the following example, the num-fn
definition is altered while
re-evaluating the map
test expression.
- On the define statement, use yy to yank into unnamed buffer
- CTRL-W CTRL-W goes to the REPL and then CTRL-W " " pastes the definition
-
" a y y yanks the
map
test expression into register a - CTRL-W CTRL-W goes to the REPL and CTRL-W " a pastes the test expression
- After redefining the definition, we can repeat step 4 to reevaluate the test expression
Finally, CTRL-W N switches the terminal buffer to normal mode, so Vim's usual commands can be used to copy out the responses.
Type i to return to insert mode.