Recommended Free Tools
iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
You can send a selected code range from Vim to a chosen tmux pane with one Visual-mode mapping. Vim does not provide a built-in operator for sending text to arbitrary tmux panes; the mapping below captures the selection, loads it into a tmux buffer, and pastes it into the pane you specify. It does not send Enter, so the receiving program gets the text without being told to run it.
First, choose the right kind of terminal
Vim’s term_sendkeys() sends text or key sequences to a job running in a Vim terminal buffer. Vim describes this as one-way remote control, and notes that the job must be in a state where the keys make sense. It is not a general way to address any unrelated tmux pane. See the Vim terminal manual.
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
TMKB T68SE Gaming Keyboard, 60% Mechanical Keyboard, LED Backlit Ultra-Compact 68 Keys Wired Mini... | $29.99 | Buy on Amazon |
| 2 |
|
tmux 2: Productive Mouse-Free Development | $21.95 | Buy on Amazon |
| 3 |
|
tmux: Productive Mouse-Free Development | $5.88 | Buy on Amazon |
If the destination is a separately managed tmux pane, use tmux to identify and target that pane. The setup below uses tmux’s buffer commands to transfer the selected text, then binds that work to a Visual-mode mapping. Vim’s Visual mode supports selecting a region and applying an operation to it; custom mappings and user-defined operators are documented in the Visual mode manual and mapping manual.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Set up a Visual-mode send mapping
This example is Vimscript glue, not a built-in Vim command or a tested cross-platform plugin. It assumes Vim can run external commands and that the tmux command is available in Vim’s environment. Replace dev:1.2 with the tmux target for your destination pane: session dev, window 1, pane 2.
#1 Best Overall
- Cool LED Backlighting: T68SE gaming keyboard is fixed lighting color.There is 19 built-in backlights mode with shortcut keys to adjust backlight brightness and speed. Due to the iterative transparent word colour of the keycap that you may receive a Mixed light or single light.
- Compact & Practical 60% Layout: T68SE mechanical keyboard features a 68-key design with separate arrow keys and commonly used control keys. The included power cord is plug-and-play. Combines practicality, full functionality and portability .
- Tactile Brown Switch: Tactile switch with a soft subtle bump and no loud click. A versatile all-rounder for office and daily use, ideal for people wanting clear keypress feedback without disruptive noise.
- Efficient & Comfortable Operation: The T68SE 60 percent keyboard based on ergonomics, scientific stepped keycap design provides maximum comfort. Support full key anti-ghosting.Keep you away from lag and enjoy efficient and smooth gaming typing.
- Compatibility & After-sales Service: Suitable for Windows 11/10/8/7/XP. Mac OS, Vista, and Linux are compatible with typing and office only.TMKB product support one year warranty, if you encounter any problems, please feel free to contact us, give you a satisfactory answer within 24 hours.
let g:vim_tmux_target = 'dev:1.2'
function! SendVisualToTmux() abort
" Reselect and yank the Visual range into the unnamed register.
normal! gvy
let text = getreg('"')
" Load the captured text into a tmux buffer, then paste it into the target.
let load_result = system('tmux load-buffer -', text)
if v:shell_error
echoerr 'tmux load-buffer failed: ' . load_result
return
endif
let paste_result = system('tmux paste-buffer -t ' . shellescape(g:vim_tmux_target))
if v:shell_error
echoerr 'tmux paste-buffer failed: ' . paste_result
return
endif
endfunction
xnoremap <leader>r :<C-U>call SendVisualToTmux()<CR>
- Add the function and mapping to your
~/.vimrc, then changeg:vim_tmux_targetto the intended session, window, and pane. - Reload the configuration with
:source ~/.vimrc, or restart Vim. - In Visual mode, select a harmless test line and press
rif your leader key is the default backslash. The mapping copies the range into a tmux buffer and pastes it into the configured pane.
The load-buffer - command reads buffer contents from standard input; paste-buffer -t directs the paste to the selected pane. These are tmux mechanisms documented in the tmux(1) manual. The mapping uses system() to connect Vim’s captured text to those commands. Check the destination before sending: text pasted into a shell or interactive program can have effects beyond appearing on screen.
What happens to Enter and multiline code?
The example does not append an Enter key. That is deliberate: pasting text and submitting it are separate actions. After the text appears, inspect it and press Enter yourself if the receiving shell or REPL should execute it. If you instead arrange to send Enter automatically, a shell may run the command immediately; an interactive program may interpret the key differently.
Selections can span multiple lines, but the receiver determines how pasted newlines behave. A shell, REPL, debugger, and editor do not necessarily handle multiline input in the same way. Test with a harmless range and confirm the destination program is ready before sending real code. Vim’s default Visual selection includes the character under the cursor, subject to the 'selection' option; see the Visual mode manual.
Free tools Windows power users keep installed
One-click scans. No signup required.
Choose a transfer method for the destination
| Method | Destination | Useful when | Boundary |
|---|---|---|---|
term_sendkeys() |
A job associated with a Vim terminal buffer | Vim owns the terminal job and you want to send it text or key sequences. | It is not a selector for arbitrary external tmux panes; the job must be ready for the input. |
tmux send-keys |
A targeted tmux pane | You need pane-directed key delivery. | Target the right pane and account for how the receiver interprets keys and newlines. |
tmux buffer plus paste-buffer |
A targeted tmux pane | You want to transfer captured text separately from targeting the receiving pane. | You must capture the intended text, choose the target, and decide separately whether to submit it. |
| A Vim mapping or operator | Depends on the command it invokes | You want a repeatable, one-action interface in the editor. | The mapping is your integration glue; its state and platform assumptions are not universal Vim behavior. |
Troubleshoot a send that does not arrive
- Nothing reaches tmux: From Vim, verify that
tmuxis on the command path and that Vim is running in an environment able to access the intended tmux server. - The wrong pane receives it: Confirm the session, window, and pane target. Try a harmless test before sending code.
- Text appears but does not run: That is expected: the example deliberately does not send Enter. Submit it manually only after reviewing the pasted text.
- Commands fail: The function reports an error from either tmux command. Check the message, target, and tmux availability; the mapping cannot make a disconnected or inaccessible tmux server reachable.
The tmux manual cited here documents pane-targeted send-keys, buffer pasting, and copy-mode selection, but its retrieved page does not clearly identify a release version. Check the manual for the tmux version installed on your system if a command behaves differently.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

