Home

Awesome

tmuxsend.vim

Vim plugin that lets you copy and paste to a different tmux pane.
Or, you can just copy to the tmux buffer for later.

<img src="https://user-images.githubusercontent.com/12980409/205471326-27ef838a-c164-42a7-a576-2f5af3be95a8.gif" width="100%"/>

Tested and working on Ubuntu, macOS and Windows WSL.

Compatible Plugins

Installation

Use your favourite plugin manager. With vim-plug,

Plug 'kiyoon/tmuxsend.vim'

With lazy.nvim,

  {
    "kiyoon/tmuxsend.vim",
    keys = {
      { "-", "<Plug>(tmuxsend-smart)", mode = { "n", "x" } },
      { "_", "<Plug>(tmuxsend-plain)", mode = { "n", "x" } },
      { "<space>-", "<Plug>(tmuxsend-uid-smart)", mode = { "n", "x" } },
      { "<space>_", "<Plug>(tmuxsend-uid-plain)", mode = { "n", "x" } },
      { "<C-_>", "<Plug>(tmuxsend-tmuxbuffer)", mode = { "n", "x" } },
    },
  },

Features and Key Bindings

The plugin does NOT come with default key bindings.
Example configs:

" vimscript config
nnoremap <silent> - <Plug>(tmuxsend-smart)	" `1-` sends a line to pane .1
xnoremap <silent> - <Plug>(tmuxsend-smart)	" same, but for visual mode block
nnoremap <silent> _ <Plug>(tmuxsend-plain)	" `1_` sends a line to pane .1 without adding a new line
xnoremap <silent> _ <Plug>(tmuxsend-plain)
nnoremap <silent> <space>- <Plug>(tmuxsend-uid-smart)	" `3<space>-` sends to pane %3
xnoremap <silent> <space>- <Plug>(tmuxsend-uid-smart)
nnoremap <silent> <space>_ <Plug>(tmuxsend-uid-plain)
xnoremap <silent> <space>_ <Plug>(tmuxsend-uid-plain)
nnoremap <silent> <C-_> <Plug>(tmuxsend-tmuxbuffer)		" `<C-_>` yanks to tmux buffer
xnoremap <silent> <C-_> <Plug>(tmuxsend-tmuxbuffer)
-- lua config
-- or, just use the lazy.nvim config so it will be lazy-loaded on key press.
local tsend_map_modes = {"n", "x"}
local tsend_map_opts = {noremap = true, silent = true}
vim.keymap.set(tsend_map_modes, "-", "<Plug>(tmuxsend-smart)", tsend_map_opts)
vim.keymap.set(tsend_map_modes, "_", "<Plug>(tmuxsend-plain)", tsend_map_opts)
vim.keymap.set(tsend_map_modes, "<space>-", "<Plug>(tmuxsend-uid-smart)", tsend_map_opts)
vim.keymap.set(tsend_map_modes, "<space>_", "<Plug>(tmuxsend-uid-plain)", tsend_map_opts)
vim.keymap.set(tsend_map_modes, "<C-_>", "<Plug>(tmuxsend-tmuxbuffer)", tsend_map_opts)
  1. All functions support normal (n) and visual (x) modes. Normal mode mappings will send a single line.
  2. Smart / plain modes.
  1. Choose pane with relative ID or unique ID (uid).
  1. Choose window by giving number >= 10.
  1. Use <C-_> to copy into the tmux buffer. You can paste using Prefix + ]
  2. Omitting the number (e.g. running -) will use the previous pane again.

Recommended tmux.conf settings

# Set the base index for windows to 1 instead of 0.
set -g base-index 1

# Set the base index for panes to 1 instead of 0.
setw -g pane-base-index 1

# Show pane details.
set -g pane-border-status top
set -g pane-border-format ' .#P (#D) #{pane_current_command} '

Recommended Nvim-Tree settings

If using the example key bindings above, it is recommended to change Nvim-Tree's keybinding (remove '-' and use 'u' instead):

require("nvim-tree").setup({
  -- ...
  view = {
    mappings = {
      list = {
        { key = "u", action = "dir_up" },
      },
    },
  },
  remove_keymaps = {
    '-',
  }
  -- ...
})

Related project