Vim plugin that lets you copy and paste to a different tmux pane.
Or, you can just copy to the tmux buffer for later.
- For interactive development, similar to Jupyter Notebook. You can paste your code on a bash shell or an ipython interpreter.
- Detects vim/neovim and ipython running, and paste within an appropriate paste mode.
Tested and working on Ubuntu, macOS and Windows WSL.
- It will detect Nvim-Tree and copy-paste the file's absolute path.
- It works great with treemux which shows Nvim-Tree within tmux! Make your terminal like an IDE.
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" } },
},
},
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)
- All functions support normal (n) and visual (x) modes. Normal mode mappings will send a single line.
- Smart / plain modes.
- smart: detect running program on the destination, and add new lines if they're shell or ipython.
- plain: do not add new line and send exactly the selected part.
- Choose pane with relative ID or unique ID (uid).
- uid makes it possible to send over sessions.
- For example,
5-
will paste selection (or current line) to the .5 pane. 5<space>-
will paste selection (or current line) to the %5 pane.- Use
set -g pane-border-format "#D"
in the tmux.conf to see the pane unique identifier.
- Choose window by giving number >= 10.
- For example,
12-
will paste selection (or current line) to window 1 pane 2. 123-
will paste selection (or current line) to window 12 pane 3.
- Use
<C-_>
to copy into the tmux buffer. You can paste usingPrefix + ]
- Omitting the number (e.g. running
-
) will use the previous pane again.
# 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} '
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 = {
'-',
}
-- ...
})
- vim-slime
- Differences: vim-slime focuses on sending to REPL for development, whereas tmuxsend.vim is for more general purpose.
- tmuxsend.vim can choose which pane to send, even in different windows, different session etc.
- tmuxsend.vim can detect the target pane's running program for a better experience (e.g. detects vim and paste in paste mode)
- tmuxsend.vim does not rely on LSP so it's lighter. Just grab the exact part you need.
- Tip: use treesitter-textobjects to easily select function/class/if/loop etc.
- tmuxsend.vim can send Nvim-Tree's files with absolute path to another pane.
- vim-screenpaste if you're using screen.