forked from lilydjwg/dotvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc.py
29 lines (26 loc) · 837 Bytes
/
vimrc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import vim
import sys
import subprocess
def echon(text):
vim.command('echon %r' % text)
def LilyPaste():
msg = 'Pasting...'
echon(msg)
vim.command('redraw')
curl = subprocess.Popen(['curl', '--compressed', '-m', '60', '-Ss', '-F', 'vimcn=<-', 'http://p.vim-cn.com'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
)
for l in vim.current.range:
curl.stdin.write(l.encode('utf-8') + b'\n')
curl.stdin.close()
url = curl.stdout.read().decode('utf-8').strip()
if not url:
vimprint('Error', 'Failed to paste code.')
ft = vim.eval('&ft')
if ft:
url = '%s/%s' % (url, ft)
vim.eval('setreg("*", %r)' % url)
echon(msg + url)
curl.wait()
def vimprint(style, text):
vim.command("echohl %s | echo '%s' | echohl None" % (style, text.replace("'", "''")))