You can send selected code from Vim to a separate tmux pane with one custom Vim mapping, but Vim does not provide a built-in tmux-send operator. The mapping is the glue: it captures the Visual-mode selection, passes the text to a tmux command aimed at a specific pane, and optionally sends Enter. This article uses tmux’s paste-buffer route so the code is inserted as text and the decision to execute it stays explicit.
First, distinguish a Vim terminal from a separate tmux pane
Vim’s term_sendkeys() sends text or key sequences to a job running in a Vim terminal buffer. Vim describes this as one-way control: the receiving job must be in a state where the keys make sense. It is useful when Vim owns the terminal job, but it is not a general way to choose an unrelated tmux pane. See the Vim terminal manual.
As an Amazon Associate I earn from qualifying purchases.
For a separately managed tmux pane, use tmux’s pane-targeted commands. The example below puts the selected text in a tmux buffer and pastes that buffer into an explicitly named pane. The custom mapping—not Vim alone—connects the editor selection to tmux. Vim supports mappings and user-defined operators; see the Vim mapping manual.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Set up a mapping that sends the Visual selection
This Vimscript mapping yanks the selected lines into register a, writes that text to a temporary file, loads it into a named tmux buffer, and pastes it into the chosen pane. It does not send Enter, so a shell will not run a command merely because this mapping completed.
#1 Best Overall
- VI VIM EDITOR KEYBOARD STICKER
- VI VIM EDITOR KEYBOARD SHORTCUT
- Hight quality keyboard sticker!
- Keyboard Stickers are made with typographical method on high-quality Matt Vinyl
- Size of individual small sticker is 11/5 x 13 mm
function! SendVisualToTmux() range
let l:target = 'mysession:main.2'
let l:file = tempname()
let l:lines = getline(line("'<"), line("'>"))
call writefile(l:lines, l:file)
call system('tmux load-buffer -b vim-send ' . shellescape(l:file))
call system('tmux paste-buffer -b vim-send -t ' . shellescape(l:target))
call delete(l:file)
endfunction
xnoremap <leader>s :<C-U>call SendVisualToTmux()<CR>
- Save the function and mapping in your Vim configuration, such as
~/.vimrc. - Replace
mysession:main.2with the target in your tmux setup. The target format identifies a session, window, and pane; verify it with your own tmux session before using the mapping. - In Vim, select the code in Visual mode, then press
<leader>s. Vim’s Visual mode applies an operation to the selected region; its exact characterwise or linewise extent is affected by the'selection'option. See the Vim Visual mode manual. - Check that the text appears in the intended pane. If the destination is a shell, press Enter yourself only after confirming the pasted command is what you meant to run.
The function is integration glue rather than a Vim or tmux built-in. It assumes Vim can invoke tmux, that the command is running in a context with access to the intended tmux server, and that the selected destination exists. The named tmux buffer is reused on each call. tmux documents paste-buffer for inserting a buffer into a specified pane; the tmux(1) manual also documents pane-targeted send-keys.
Choose whether the selection should run
Pasting text and submitting it are different actions. The mapping above only pastes; this is the safer default for code that may span lines or for destinations such as a REPL or debugger that interpret input differently from a shell. If you want automatic submission, add a separate, deliberate action after the paste and test it with harmless input first. A newline or Enter can execute a shell command or trigger behavior in another interactive program.
Rank #2
- 【Large Mouse Pad】Our extra-large mouse pad 31.4×11.8×0.07 inch(800×300×2 mm) is perfect for use as a desk mat, keyboard and mouse pad, or keyboard mat, offering you unparalleled comfort and support during long gaming sessions or work days.
- 【Shortcut Rference to VIM】Extensive compilation of commonly used command lines for VIM.This quick reference guide is designed to reduce programming time on VIM.Perfect for beginners and experienced programmer.
- 【Highly durable design】-The small office&gaming mouse pad is designed with high stretch silk precision locking edges to avoid loose threads on the cloth. Ensure Prolonged Use Without Deformation And Degumming.
- 【 Non-slip Rubber Base】-Dense shading and anti-slip natural rubber base can firmly grip the desktop. Premium soft material for your comfort and mouse-control.
- 【Ultra Smooth Surface】 Mouse Pad Designed With Superfine Fiber Braided Material, Smooth Surface Will Provide Smooth Mouse Control And Pinpoint Accuracy. Optimized For Fast Movement While Maintaining Excellent Speed And Control During Your Work Or Game.
When to use the other routes
| Route | Destination | Best fit | Important boundary |
|---|---|---|---|
term_sendkeys() |
A job attached to a Vim terminal buffer | Vim itself owns the terminal job | Does not select an arbitrary separate tmux pane; the job must be ready for the sent keys. |
tmux send-keys |
A targeted tmux pane | Sending particular keystrokes to a known pane | Targeting and interpretation of keys, including newline behavior, must be handled deliberately. |
tmux buffer and paste-buffer |
A targeted tmux pane | Transferring a block as text, with submission left separate | Requires a way to capture the text and name the intended pane. |
| Vim custom mapping or operator | Depends on the command it invokes | Making the transfer a one-action editor workflow | It is user configuration, so its target, shell access, and selection semantics are yours to define. |
tmux also supports selecting text in copy mode and piping that selection with copy-pipe, which is useful when the selection originates inside tmux rather than Vim. The tmux manual documents these mechanisms alongside buffer pasting.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Quick Recap
Best Value
- Cherry profile keycaps offer a sculpted shape that conforms to finger contours, providing a comfortable and familiar typing angle favored by many enthusiasts.
- The dye-sublimation printing technique infuses legends directly into the PBT material, creating sharp, long-lasting markings that resist wear from frequent use.
- Features a VIM editor-inspired theme with distinct color accents and text legends, appealing to programmers and users familiar with this popular coding environment.
- Made from white PBT plastic that offers a textured feel and maintains its color over time, resisting the shiny appearance that can develop on other materials.
- This comprehensive 131-key set includes specialized keys like 1.75U and 2U shifts, ensuring compatibility with a wide range of keyboard layouts from full-size to compact designs.
Rank #4
- Multi-Device Connectivity: Effortlessly connect and switch between up to 3 devices (Android, iOS, Windows) with ease, perfect for multitaskers who need to move between devices quickly for seamless workflow and productivity
- Comfortable and Responsive Typing: Features 12 customizable shortcut keys and a 1.3mm low travel distance to provide a comfortable, quiet, and responsive typing experience, making it ideal for both casual use and long work sessions
- Ultra-Slim and Lightweight Design: With a slim profile and a lightweight design of just 180g, this keyboard is perfect for on-the-go professionals or those who need a portable keyboard for their tablet, laptop, or mobile device
- Long Battery Life: Enjoy up to 60 hours of continuous use on a single charge with the rechargeable battery, allowing you to work, create, and type for extended periods without the need for constant recharging or battery swaps
- Flexible Connectivity Options: Choose between Bluetooth or USB-C for secure, reliable, and quick connectivity with your devices, ensuring you have the flexibility to use it in any workspace, whether at home, in the office, or on the go
Rank #3
- Large Size: 800 x 300 mm + 2mm thickness adapt to all surfaces
- Non-Slip Base: The mouse pad has a non-slip base to ensure it stays in place on your desk, preventing it from sliding during use.
- Durable Stitched Edge: The circle edge stitching prevents the top layer from fraying and ensures the mousepad for long time use.
- Versatile Use: Not only suitable for office and everyday use, but also perfect for gamers and designers alike. It can also be a special gift for your family and friends.
Troubleshoot a mapping that does not reach the pane
- No text appears: Confirm Vim can run
tmuxand can reach the tmux server. Check that the session, window, and pane intargetare correct. - The wrong range appears: Select again in Visual mode and check whether you intended a characterwise or linewise selection. Vim’s
'selection'setting affects the included boundary. - The destination reacts unexpectedly: Do not add Enter by default. Some receiving programs treat pasted multiline input or key sequences as commands.
- The mapping behaves differently in your environment: The manuals establish the underlying Vim and tmux features, but do not establish that this custom Vimscript works identically across all operating systems, shells, or versions. Adapt and test it in a harmless pane before relying on it.
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.




