Skip to content

Instantly share code, notes, and snippets.

@bfredl
Last active August 29, 2015 14:06
Show Gist options
  • Save bfredl/888e2b7c2b378d6953ee to your computer and use it in GitHub Desktop.
Save bfredl/888e2b7c2b378d6953ee to your computer and use it in GitHub Desktop.
from subprocess import Popen, PIPE
class NvimClipboard(object):
def __init__(self, vim):
self.provides = ['clipboard']
def sel_name(self, reg):
return 'clipboard' if reg == '+' else 'primary'
def clipboard_get(self, reg):
txt = Popen(['xclip', '-selection', self.sel_name(reg), '-o'], stdout=PIPE).communicate()[0]
# emulate vim behavior
if txt.endswith('\n'):
txt = txt[:-1]
regtype = 'V'
else:
regtype = 'v'
return txt.split('\n'), regtype
def clipboard_set(self, lines, regtype, reg):
txt = '\n'.join([line for line in lines])
if regtype == 'V':
txt = txt + '\n'
_cmd = ['xclip', '-selection', self.sel_name(reg)]
Popen(_cmd, stdin=PIPE).communicate(txt)
@bfredl
Copy link
Author

bfredl commented Sep 15, 2014

Oops, lost the import when copying, it should work now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment