Last active
May 19, 2022 04:42
-
-
Save ljjjustin/f99171b337213d5e00de6ac0c87b631b to your computer and use it in GitHub Desktop.
vim remote copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to setup? | |
1. local: add sshconfig to your ~/。ssh/config | |
2. local: copy pbcopy.plist to HOME/Library/LaunchAgents/ and load it with: | |
launchctl load -w $HOME/Library/LaunchAgents/pbcopy.plist | |
3. remote: add vimrc to your remote server's vim config file ~/.vimrc | |
4. remote: copy pbcopy to your remote server and make it excutable | |
chmod +x /usr/local/bin/pbcopy | |
5. remote: run vim and yank | |
6. local: paste the yanked content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 1 ]; then | |
cat $1 | nc localhost 22222 | |
else | |
[[ -p /dev/stdin ]] && { cat | nc localhost 22222; } | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>localhost.pbcopy</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/bin/pbcopy</string> | |
</array> | |
<key>inetdCompatibility</key> | |
<dict> | |
<key>Wait</key> | |
<false/> | |
</dict> | |
<key>Sockets</key> | |
<dict> | |
<key>Listeners</key> | |
<dict> | |
<key>SockServiceName</key> | |
<string>22222</string> | |
<key>SockNodeName</key> | |
<string>127.0.0.1</string> | |
</dict> | |
</dict> | |
</dict> | |
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Host * | |
RemoteForward 22222 127.0.0.1:22222 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s:selfpid = getpid() | |
function! s:pbcopy() | |
let l:path = printf("/tmp/%d.pbcopy", s:selfpid) | |
let l:command = printf("/usr/local/bin/pbcopy %s", l:path) | |
let l:content = split(getreg('"'), "\n", 1) | |
call writefile(l:content, l:path) | |
call system(l:command) | |
endfunction | |
function! s:cleanup() | |
let l:path = printf("/tmp/%d.pbcopy", s:selfpid) | |
let l:command = printf("/bin/rm -f %s", l:path) | |
call system(l:command) | |
endfunction | |
augroup pbcopy | |
au! | |
au TextYankPost * if v:event.operator ==# 'y' | call s:pbcopy() | endif | |
au VimLeave * call s:cleanup() | |
augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment