Skip to content

Commit

Permalink
Add ability to automatically send yanked text to Clipper
Browse files Browse the repository at this point in the history
Works on Neovim thanks to the `TextYankPost` autocommand. Can opt out
via `'g:ClipperAuto'`.

This aligns with the set-up I have in recent versions of tmux. Note that
I've explicitly scoped it to explicit yank operations (not deletions or
changes). Given that one tends to yank a lot in Vim, for this to be
usually helpful but with an escape hatch in case the behavior is not
what you want in a specific instance, it's important to pair it with a
tool like Alfred that remembers recent clipboard history, so that you
can go back to a previous entry if you end up inadvertently overwriting
something.
  • Loading branch information
wincent committed Aug 25, 2017
1 parent 6c13e89 commit 35d15d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 17 additions & 1 deletion doc/clipper.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ runs in the background providing a service that exposes the local clipboard to
tmux sessions and other processes running both locally and remotely.

Specifically, vim-clipper provides a |:Clip| command, to send the last-yanked
text to Clipper, and it sets up a <leader>y mapping that calls |:Clip|.
text to Clipper, it sets up a <leader>y mapping that calls |:Clip|.
Additionally, if the |TextYankPost| |autocommand| is available, it will send
the last-yanked text to Clipper automatically.


INSTALLATION *clipper-installation*
Expand Down Expand Up @@ -82,6 +84,14 @@ OPTIONS *clipper-options*
To connect via a UNIX domain socket, set the port number to 0, and provide
the path to the socket using the |g:ClipperAddress| option.

*g:ClipperAuto*
|g:ClipperAuto| boolean (default: 1)

Controls whether to use the |TextYankPost| autocommand to route yanked text
to Clipper automatically. To prevent this, set to 0 in your |.vimrc|: >
let g:ClipperAuto=0
<
*g:ClipperMap*
|g:ClipperMap| boolean (default: 1)

Expand Down Expand Up @@ -168,6 +178,12 @@ vim-clipper is written and maintained by Greg Hurrell <greg@hurrell.net>.

HISTORY *clipper-history*

2.0 (25 August 2017)

- Add ability to automatically send yanked text to Clipper using the
|TextYankPost| autocommand, and the corresponding |g:ClipperAuto| setting to
provide an opt-out mechanism.

1.0 (3 June 2016)

- Rename |<Plug>ClipperClip| to |<Plug>(ClipperClip)|.
Expand Down
8 changes: 8 additions & 0 deletions plugin/clipper.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ if s:map
endif
nnoremap <Plug>(ClipperClip) :Clip<CR>
let s:auto=get(g:, 'ClipperAuto', 1)
if s:auto && exists('##TextYankPost')
augroup Clipper
autocmd!
autocmd TextYankPost * if v:event.operator ==# 'y' | call clipper#private#clip() | endif
augroup END
endif

" Restore 'cpoptions' to its former value.
let &cpoptions=s:cpoptions
unlet s:cpoptions

0 comments on commit 35d15d7

Please sign in to comment.