This plugin can be used to send selected snippets of code to a specified pane inside tmux, where presumably an interpreter (Read-Eval-Print Loop) is running.
A demo can be seen here.
To use the plugin, include:
require('tmux-repl')
in your visrc.lua.
First, you need to specify the target pane for the current window, to which the selected snippets will be sent. You can do it by either of the two commands:
repl-set [PANE_ID]-- set an existing pane identified byPANE_IDas the target pane; if noPANE_IDis provided, the marked pane is used,repl-new [CMD]-- open a new pane in vertical split and set it to the target pane; optionally, the commandCMDwill be run inside the new pane.
For example you can use commands like :repl-new python or :repl-new R
to open the interpreter for the respective language.
repl-send-- sends the current selection to the target pane,repl-sendln [TEXT]-- sendsTEXTto the target pane.
The latter is useful e.g. for calling :repl-sendln make to a shell to
recompile your project - you can set a keybinding for that.
Setting some keybindings in visrc.lua will allow you to use the
interpreters efficiently:
vis.events.subscribe(vis.events.INIT, function()
-- ... (other initial settings)
vis:command("map! normal <C-r> :repl-new")
vis:command("map! normal <C-e> :repl-set<Enter>")
vis:command("map! visual <C-e> :repl-send<Enter><vis-mode-normal>")
end)
The script relies on tmux's send-keys command called from the
shell. Although it tries to correctly escape all whitespace and special
characters and has been tested with several languages (Python, R,
Haskell), there might still be bugs related to that.
The implementation of a similar solution for Vim was described step by step here: Executing code chunks from Vim