Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).
created March 17, 2013 · complexity basic · version 7.0
When scripting Vim using Python, the following error may occur when passing a utf-8 encoded string from Python to Vim:
:py print u'echo "\u2026"' Traceback (most recent call last): File "<string>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 6: ordinal not in range(128)
The following example shows how to avoid the problem:
python << EOS uniStr = u"\u2026" str = uniStr.encode( vim.eval("&encoding") ) print str EOS
Or, the following one liner:
:py print u"\u2026".encode( vim.eval("&encoding") )
See also
Edit
- Vim mailing list origin of this tip: see discussion for more information
Comments
Edit
Community content is available under CC-BY-SA
unless otherwise noted.