tpope / vim-tbone

tbone.vim: tmux basics
http://www.vim.org/scripts/script.php?script_id=4488
397 stars 17 forks source link

Is it possible to :Tyank on a visual selection? #11

Open axelson opened 10 years ago

axelson commented 10 years ago

My use case is that I would like to yank a word or phrase that wraps around in a vim vertical split, so yanking directly with tmux will result in the other vertical buffer's text yanking as well. So on the surface :Tyank seems like it would solve the issue, but it seems to always yank a full line (or more if you give it a range).

Am I missing something? Or would that be an enhancement to vim-tbone?

tpope commented 10 years ago

Not possible with the current implementation. The appropriate interface for such an operation would be a map, and I'm not too enthused about opening that can of worms.

axelson commented 10 years ago

Okay, that is understandable. Thanks for the plugin (and especially for all of your other vim plugins).

On Thu, Oct 23, 2014 at 12:08 PM, Tim Pope notifications@github.com wrote:

Not possible with the current implementation. The appropriate interface for such an operation would be a map, and I'm not too enthused about opening that can of worms.

— Reply to this email directly or view it on GitHub https://github.com/tpope/vim-tbone/issues/11#issuecomment-60317354.

rainerborene commented 8 years ago
function! s:tmux_load_buffer()
  let [lnum1, col1] = getpos("'<")[1:2]
  let [lnum2, col2] = getpos("'>")[1:2]
  let lines = getline(lnum1, lnum2)
  let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
  let lines[0] = lines[0][col1 - 1:]
  let tempfile = tempname()
  call writefile(lines, tempfile, "a")
  call system('tmux load-buffer '.tempfile)
  call delete(tempfile)
endfunction
vnoremap <silent> <leader>y :call <sid>tmux_load_buffer()<cr>

This works well for me.

@tpope could you merge this piece of code on vim-tbone?

ostrain commented 3 years ago

Here's another way I came up with to do this, without writing a temp file:

vnoremap <leader>y "zy:tabnew<CR>"zP:w !xargs -0 tmux set-buffer<CR><CR>:bdelete!<CR>

Basically it yanks the selection to an arbitrary register (I'm using "z), opens a new (temp) buffer in a new tab, pastes in the contents of the register, uses xargs to pass the contents of the buffer to tmux set-buffer, then close the temp buffer/tab. It doesn't require vim-tbone to be installed.