October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Send a Visual Selection From Vim to a tmux Pane With One Operator

Vim has no built-in tmux-send operator, but a custom mapping can transfer a Visual selection to a specific pane. This example pastes text without submitting it.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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 and Vim Editor Keyboard Sticker
  • 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>
  1. Save the function and mapping in your Vim configuration, such as ~/.vimrc.
  2. Replace mysession:main.2 with 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.
  3. 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.
  4. 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
Sale
excovip Mouse Pad for Vim, 31.4x11.7x0.07 inch Extended Large Cheat Sheet Mousepad PC Office Spreadsheet Keyboard Shortcut Mouse Mat with Non-Slip Stitched Edge 0326
  • 【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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
RXJPASD 131 Keys Vim White PBT Dye-Sub Cherry Set
  • 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
Lenovo Multi-Device Wireless Bluetooth Keyboard, Iron Grey
  • 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
ablieve Large Mouse Pad XL - Unique Desk Mouse Mat with Built-in Vim Cheat Sheet - Easy to Clean Mouse and Keyboard Pad with Comprehensive Vim Shortcut for Software Engineers
  • 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 tmux and can reach the tmux server. Check that the session, window, and pane in target are 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.