1 # From http://slobin.pp.ru/vim/_vimrc.html
2 # Adapted to python3 by Oleg Broytman <phd@phdru.name>
4 import sys, rlcompleter, unicodedata, vim
5 from itertools import *
6 vim_complete = rlcompleter.Completer().complete
9 """Implementation of CompList() function"""
10 arglead = vim.eval("a:ArgLead")
11 fence = int(vim.eval("match(a:ArgLead, '\(\w\|\.\)*$')"))
12 left, right = arglead[:fence], arglead[fence:]
14 completions = (vim_complete(right, i) for i in count())
15 candidates = list(takewhile(bool, completions))
18 suggestions = [left + x for x in candidates]
19 vim.command("return " + repr(suggestions))
21 def vim_calc(command):
22 """Implementation of :Calc command"""
25 result = eval(command)
27 if sys.version_info[0] == 2:
28 exec(command in globals(), locals())
30 exec(command, globals(), locals())
35 xx = ''.join(['\\x%02x' % ord(x) for x in str(_)])
36 vim.command('let @" = "%s"' % xx)
38 def vim_pydo(command):
39 """Implementation of :Pydo command"""
40 codeobj = compile(command, "command", "eval")
41 line1 = vim.current.range.start
42 line2 = vim.current.range.end
44 for numz in range(line1, line2+1):
45 line = vim.current.buffer[numz-delta]
46 if sys.version_info[0] == 2:
47 uline = unicode(line, vim.eval('&fileencoding'))
52 result = eval(codeobj, globals(), locals())
53 if result is None or result is False:
54 del vim.current.buffer[numz-delta]
57 if isinstance(result, list) or isinstance(result, tuple):
58 result = " ".join(map(str, result))
61 vim.current.buffer[numz-delta] = result
63 def vim_unicode_name():
65 char = vim.eval("matchstr(getline('.'), '.', col('.') - 1)")
66 if sys.version_info[0] == 2:
67 print(unicodedata.name(char.decode(vim.eval("&encoding"))))
69 print(unicodedata.name(char))
70 except (AttributeError, ValueError) as target:
71 print("%s: %s" % (target.__class__.__name__, target))