├── .gitignore ├── .mailmap ├── LICENSE.txt ├── README.txt ├── autoload ├── clipper.vim └── clipper │ └── private.vim ├── doc ├── .gitignore └── clipper.txt └── plugin └── clipper.vim /.gitignore: -------------------------------------------------------------------------------- 1 | /*.zip 2 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Greg Hurrell 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2015-present Greg Hurrell. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright notice, 9 | this list of conditions and the following disclaimer in the documentation 10 | and/or other materials provided with the distribution. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 16 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | doc/clipper.txt -------------------------------------------------------------------------------- /autoload/clipper.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2018-present Greg Hurrell. All rights reserved. 2 | " Licensed under the terms of the BSD 2-clause license. 3 | 4 | function! clipper#set_invocation(method) abort 5 | call clipper#private#set_invocation(a:method) 6 | endfunction 7 | -------------------------------------------------------------------------------- /autoload/clipper/private.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2015-present Greg Hurrell. All rights reserved. 2 | " Licensed under the terms of the BSD 2-clause license. 3 | 4 | function! clipper#private#set_invocation(method) abort 5 | if !exists('s:invocation') 6 | let s:invocation=a:method 7 | endif 8 | endfunction 9 | 10 | function! clipper#private#clip() abort 11 | if exists('s:invocation') && s:invocation != '' 12 | call system(s:invocation, @0) 13 | elseif clipper#private#executable() != '' 14 | let l:executable = clipper#private#executable() 15 | let l:address = get(g:, 'ClipperAddress', 'localhost') 16 | let l:port = +(get(g:, 'ClipperPort', 8377)) " Co-erce to number. 17 | if l:port 18 | " nc 19 | call system(l:executable . ' ' . l:address . ' ' . l:port, @0) 20 | else 21 | " nc -U 22 | call system(l:executable . ' -U ' . l:address, @0) 23 | endif 24 | else 25 | echoerr 'Clipper: nc executable does not exist' 26 | endif 27 | endfunction 28 | 29 | let s:executable='' 30 | 31 | function! clipper#private#executable() abort 32 | if s:executable == '' && executable('nc') == 1 33 | " Try to figure out whether -N switch is supported and required. 34 | " Examples: 35 | " - Ubuntu, FreeBSD and similar: 36 | " Supports and requires -N: 37 | " "shutdown(2) the network socket after EOF on the input" 38 | " http://manpages.ubuntu.com/manpages/bionic/man1/nc_openbsd.1.html 39 | " https://www.freebsd.org/cgi/man.cgi?nc 40 | " - Darwin: 41 | " Supports but does not require -N; it does something else: 42 | " "Number of probes to send before generating a write timeout event" 43 | " - CentOS etc: 44 | " Does not support or need -N. 45 | let l:help = system('nc -h') 46 | if match(l:help, '\c\v\s-N\s.+shutdown>') != -1 47 | let s:executable = 'nc -N' 48 | else 49 | let s:executable = 'nc' 50 | endif 51 | endif 52 | return s:executable 53 | endfunction 54 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | -------------------------------------------------------------------------------- /doc/clipper.txt: -------------------------------------------------------------------------------- 1 | *clipper.txt* Clipper plug-in for Vim *clipper* *vim-clipper* 2 | 3 | CONTENTS *clipper-contents* 4 | 5 | 1. Intro |clipper-intro| 6 | 2. Installation |clipper-installation| 7 | 3. Commands |clipper-commands| 8 | 4. Options |clipper-options| 9 | 5. Functions |clipper-functions| 10 | 6. Mappings |clipper-mappings| 11 | 7. Website |clipper-website| 12 | 8. License |clipper-license| 13 | 9. Development |clipper-development| 14 | 10. Authors |clipper-authors| 15 | 11. History |clipper-history| 16 | 17 | 18 | INTRO *clipper-intro* 19 | 20 | "clipper (noun) 21 | an instrument for cutting or trimming small pieces off things." 22 | 23 | *clipper-features* 24 | vim-clipper provides integration between Vim and Clipper 25 | (https://github.com/wincent/clipper), which is an macOS "launch agent" that 26 | runs in the background providing a service that exposes the local clipboard to 27 | tmux sessions and other processes running both locally and remotely. 28 | 29 | Specifically, vim-clipper provides a |:Clip| command, to send the last-yanked 30 | text to Clipper, it sets up a y mapping that calls |:Clip|. 31 | Additionally, if the |TextYankPost| |autocommand| is available, it will send 32 | the last-yanked text to Clipper automatically. 33 | 34 | vim-clipper supports both Vim and Neovim. nvim-clipper 35 | (https://github.com/wincent/nvim-clipper) is a streamlined, Lua-only 36 | equivalent designed to support only Neovim. 37 | 38 | 39 | INSTALLATION *clipper-installation* 40 | 41 | To install vim-clipper, use your plug-in management system of choice. 42 | 43 | If you don't have a "plug-in management system of choice", I recommend 44 | Pathogen (https://github.com/tpope/vim-pathogen) due to its simplicity and 45 | robustness. Assuming that you have Pathogen installed and configured, and that 46 | you want to install vim-clipper into `~/.vim/bundle`, you can do so with: > 47 | 48 | git clone https://github.com/wincent/vim-clipper.git ~/.vim/bundle/vim-clipper 49 | 50 | Alternatively, if you use a Git submodule for each Vim plug-in, you could do 51 | the following after `cd`-ing into the top-level of your Git superproject: > 52 | 53 | git submodule add https://github.com/wincent/vim-clipper.git ~/vim/bundle/vim-clipper 54 | git submodule init 55 | 56 | To generate help tags under Pathogen, you can do so from inside Vim with: > 57 | 58 | :call pathogen#helptags() 59 | 60 | 61 | COMMANDS *clipper-commands* 62 | 63 | *:Clip* 64 | :Clip Sends the last-yanked text to Clipper. 65 | 66 | 67 | OPTIONS *clipper-options* 68 | 69 | *g:ClipperAddress* 70 | |g:ClipperAddress| string (default: localhost) 71 | 72 | Specifies the address at which to connect to the Clipper daemon. To override 73 | from the default of "localhost", set it in your |.vimrc|. The main reason 74 | you would want to do this is to make Clipper connect to a UNIX domain 75 | socket: > 76 | 77 | let g:ClipperAddress=~/.clipper.sock 78 | < 79 | Note that if you want to connect using a UNIX domain socket, you must also 80 | set |g:ClipperPort| to 0. 81 | 82 | If |g:ClipperAddress| and |g:ClipperPort| provide insufficient 83 | configurability (for example, because you are using a version of `nc` that 84 | doesn't support UNIX sockets and want to use an alternative like 85 | `socat - UNIX-CLIENT:$SOCKET`), then you can use |clipper#set_invocation()| 86 | to provide an entirely custom string. 87 | 88 | *g:ClipperPort* 89 | |g:ClipperPort| number (default: 8377) 90 | 91 | Specifies the port on which to connect to the Clipper daemon. To override 92 | from the default of port 8377, set it in your |.vimrc|: > 93 | 94 | let g:ClipperPort=31337 95 | < 96 | To connect via a UNIX domain socket, set the port number to 0, and provide 97 | the path to the socket using the |g:ClipperAddress| option. 98 | 99 | If |g:ClipperAddress| and |g:ClipperPort| provide insufficient 100 | configurability (for example, because you are using a version of `nc` that 101 | doesn't support UNIX sockets and want to use an alternative like 102 | `socat - UNIX-CLIENT:$SOCKET`), then you can use |clipper#set_invocation()| 103 | to provide an entirely custom string. 104 | 105 | *g:ClipperAuto* 106 | |g:ClipperAuto| boolean (default: 1) 107 | 108 | Controls whether to use the |TextYankPost| autocommand to route yanked text 109 | to Clipper automatically. To prevent this, set to 0 in your |.vimrc|: > 110 | 111 | let g:ClipperAuto=0 112 | < 113 | *g:ClipperMap* 114 | |g:ClipperMap| boolean (default: 1) 115 | 116 | Controls whether to set up the |(ClipperClip)| mapping. To prevent any 117 | mapping from being configured, set to 0 in your |.vimrc|: > 118 | 119 | let g:ClipperMap=0 120 | < 121 | *g:ClipperLoaded* 122 | |g:Clipper| any (no default) 123 | 124 | To prevent vim-clipper from being loaded, set |g:ClipperLoaded| to any value 125 | in your |.vimrc|. For example: > 126 | 127 | let g:ClipperLoaded=1 128 | 129 | 130 | FUNCTIONS *clipper-functions* 131 | 132 | 133 | |clipper#set_invocation()| *clipper#set_invocation()* 134 | 135 | Provide a completely custom string to invoke an arbitrary executable with 136 | arguments. This overrides the automatic invocation that would usually be 137 | created using `nc` and the values of |g:ClipperAddress| and |g:ClipperPort|. 138 | This may be necessary in environments where you want to use a UNIX domain 139 | socket but the local version of `nc` does not support the `-U` switch. For 140 | example: > 141 | 142 | call clipper#set_invocation('socat - UNIX-CLIENT:/path/to/socket') 143 | < 144 | Note: This is a function and not a setting for security reasons; only the 145 | first call to |clipper#set_invocation()| will have any effect. In this way, 146 | you can place the call near the start of your |vimrc| without having to 147 | worry that a malicious plug-in will later overwrite it with something 148 | nefarious (important because whatever is passed to this function will be 149 | blindly executed with the |system()| function). 150 | 151 | As such, even if you don't want to use this feature, it is a good 152 | idea to lock it down by calling `clipper#set_invocation('')` in your 153 | |vimrc|. 154 | 155 | 156 | MAPPINGS *clipper-mappings* 157 | 158 | *ClipperClip* 159 | *(ClipperClip)* 160 | vim-clipper maps y to |(ClipperClip)|, which sends the last-yanked 161 | text to Clipper. To use an alternative mapping instead, create a different one 162 | in your |.vimrc| instead using |:nmap|: > 163 | 164 | " Instead of y, use x. 165 | nmap x (ClipperClip) 166 | 167 | Note that vim-clipper will not try to set up its y mapping if any of 168 | the following are true: 169 | 170 | - A mapping for y already exists. 171 | - An alternative mapping for |(ClipperClip)| has already been set up from 172 | a |.vimrc|. 173 | - The mapping has been suppressed by setting |g:ClipperMap| to 1 in your 174 | |.vimrc|. 175 | 176 | 177 | WEBSITE *clipper-website* 178 | 179 | Source code: 180 | 181 | https://github.com/wincent/vim-clipper 182 | 183 | Official releases are listed at: 184 | 185 | http://www.vim.org/scripts/script.php?script_id=5217 186 | 187 | 188 | LICENSE *clipper-license* 189 | 190 | Copyright 2015-present Greg Hurrell. All rights reserved. 191 | 192 | Redistribution and use in source and binary forms, with or without 193 | modification, are permitted provided that the following conditions are met: 194 | 195 | 1. Redistributions of source code must retain the above copyright notice, 196 | this list of conditions and the following disclaimer. 197 | 2. Redistributions in binary form must reproduce the above copyright notice, 198 | this list of conditions and the following disclaimer in the documentation 199 | and/or other materials provided with the distribution. 200 | 201 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 202 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 203 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 204 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 205 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 206 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 207 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 208 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 209 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 210 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 211 | POSSIBILITY OF SUCH DAMAGE. 212 | 213 | DEVELOPMENT *clipper-development* 214 | 215 | Contributing patches ~ 216 | 217 | Patches can be sent via mail to greg@hurrell.net, or as GitHub pull requests 218 | at: https://github.com/wincent/vim-clipper/pulls 219 | 220 | Cutting a new release ~ 221 | 222 | At the moment the release process is manual: 223 | 224 | - Perform final sanity checks and manual testing 225 | - Update the |clipper-history| section of the documentation 226 | - Verify clean work tree: 227 | > 228 | git status 229 | < 230 | - Tag the release: 231 | > 232 | git tag -s -m "$VERSION release" $VERSION 233 | < 234 | - Publish the code: 235 | > 236 | git push origin main --follow-tags 237 | git push github main --follow-tags 238 | < 239 | - Produce the release archive: 240 | > 241 | git archive -o vim-clipper-$VERSION.zip HEAD -- . 242 | < 243 | - Upload to http://www.vim.org/scripts/script.php?script_id=5217 244 | 245 | 246 | AUTHORS *clipper-authors* 247 | 248 | vim-clipper is written and maintained by Greg Hurrell . 249 | Other contributors that have submitted patches include, in alphabetical order: 250 | 251 | J. Eduardo 252 | 253 | This list produced with: 254 | 255 | :read !git shortlog -s HEAD | grep -v 'Greg Hurrell' | cut -f 2-3 | column -c 72 | expand | sed -e 's/^/ /' 256 | 257 | 258 | HISTORY *clipper-history* 259 | 260 | 2.2 (8 December 2020): 261 | 262 | - Attempt to autodetect when host platform's `nc` executable requires the `-N` 263 | switch (https://github.com/wincent/vim-clipper/pull/3). 264 | - Make autodetection work case-insensitively (patch from J Eduardo, 265 | https://github.com/wincent/vim-clipper/pull/5). 266 | 267 | 2.1 (6 March 2019) 268 | 269 | - Add ability to customize invocation with |clipper#set_invocation()|. 270 | 271 | 2.0 (25 August 2017) 272 | 273 | - Add ability to automatically send yanked text to Clipper using the 274 | |TextYankPost| autocommand, and the corresponding |g:ClipperAuto| setting to 275 | provide an opt-out mechanism. 276 | 277 | 1.0 (3 June 2016) 278 | 279 | - Rename |ClipperClip| to |(ClipperClip)|. 280 | - Add |g:ClipperAddress| and support for connecting to the Clipper daemon via 281 | a UNIX domain socket. 282 | 283 | 0.1 (6 July 2015) 284 | 285 | - Initial release, extracted from my dotfiles 286 | (https://github.com/wincent/wincent). 287 | 288 | 289 | ----------------------------------------------------------------------------- 290 | vim:tw=78:ft=help: 291 | -------------------------------------------------------------------------------- /plugin/clipper.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2015-present Greg Hurrell. All rights reserved. 2 | " Licensed under the terms of the BSD 2-clause license. 3 | 4 | " Provide users with means to prevent loading, as recommended in `:h 5 | " write-plugin`. 6 | if exists('g:ClipperLoaded') || &compatible || v:version < 700 7 | finish 8 | endif 9 | let g:ClipperLoaded=1 10 | 11 | " Temporarily set 'cpoptions' to Vim default as per `:h use-cpo-save`. 12 | let s:cpoptions=&cpoptions 13 | set cpoptions&vim 14 | 15 | command! Clip call clipper#private#clip() 16 | 17 | let s:map=get(g:, 'ClipperMap', 1) 18 | if s:map 19 | if !hasmapto('(ClipperClip)') && maparg('y', 'n') ==# '' 20 | nmap y (ClipperClip) 21 | endif 22 | endif 23 | nnoremap (ClipperClip) :Clip 24 | 25 | let s:auto=get(g:, 'ClipperAuto', 1) 26 | if s:auto && exists('##TextYankPost') 27 | augroup Clipper 28 | autocmd! 29 | autocmd TextYankPost * if v:event.operator ==# 'y' | call clipper#private#clip() | endif 30 | augroup END 31 | endif 32 | 33 | " Restore 'cpoptions' to its former value. 34 | let &cpoptions=s:cpoptions 35 | unlet s:cpoptions 36 | --------------------------------------------------------------------------------