A Vim/NeoVim plugin for sending selections and lines to a terminal
This plugin was based on vim-tidal, which was itself originally based on vim-slime.
If you are using Vim8 or NeoVim, you can use the native Terminal feature instead of tmux. Read the Configuration section on how to enable it.
These are some of the commands that can be run from Vim command line:
-
:<range>TermSend: Send a[range]of lines. If no range is provided the current line is sent. -
:TermSend1 {text}: Send a single line of text specified on the command line. -
:TermOpen: Open a terminal with the default command (provided in g:send2term_cmd) -
:TermRun: Open a terminal with a command provided by the user -
:TermClose: Close the terminal buffer, while allowing it to be reopened later like:close -
:TermQuit: Quit the terminal, killing the buffer and any running processes like:quit -
:TermToggle: if no terminal exists, open a new terminal prompting for a command to run. If a terminal is open, close it. if the terminal exists but is closed, then show that terminal buffer in a split.
Using one of these key bindings you can send lines to Send2Term:
<c-e>(Control+E): Send current inner paragraph.<leader>ss: Send current visually selected block or current inner paragraph<leader>sl: Send current line<leader>se<motion>: Send the selection motion (i.e. seip will replicate the behaviour of ss)<leader>st: run:TermToggle<leader>sr: run:TermRun<leader>so: run:TermOpen<leader>sc: run:TermClose<leader>sq: run:TermQuit
<c-e> can be called on either Normal, Visual, Select or Insert mode, so it is
probably easier to type than <leader>ss.
By default, vim-send2term uses bash as the command to launch in the terminal.
You can either then run your repl program in the bash window, or specify another command to use with g:send2term_cmd.
For example, if you wanted to launch python by default, you could use:
let g:send2term_cmd = "python3"You could also use :TermRun or :TermToggle and enter the command in the text input window there
If you want :TermToggle to use the default command, rather than
prompting for a command to run, you can do:
let g:send2term_toggle_default_cmd = 1By default, there are two normal keybindings and one for visual blocks using
your <leader> key. If you don't have one defined, set it on your
.vimrc script with let mapleader=" ", for example.
If you don't like some of the bindings or want to change them, add this line to disable them:
let g:send2term_no_mappings = 1See section Mappings on plugin/send2term.vim and copy the
bindings you like to your .vimrc file and modify them.
On both Vim (version 8 or above) and NeoVim use the native terminal
Open a file, write and send a line of code to send2term, and the send2term terminal will open in a window below your editor.
Use standard vim window navigation controls to focus the terminal (ie <C-w> down/up)
You can learn more about the native Vim terminal here:
https://vimhelp.org/terminal.txt.html
When sending a paragraph or a single line, vim-send2term will "flash" the selection
for some milliseconds. By default duration is set to 150ms, but you can modify
it by setting the g:send2term_flash_duration variable.
Write the paste buffer to an external text file:
let g:send2term_paste_file = "/tmp/send2term_paste_file.txt"For customizing the startup script for defining helper functions, see below.
Refer to the LICENSE file