Don't hesitate reading the whole thread to understand better how vim deals with encoding, and also read :he encoding
*[https://groups.google.com/forum/?fromgroups=#!searchin/vim_use/python$20utf-8/vim_use/XXVGOuPkszQ/K6LmCqM2GKAJ Vim mailing list] origin of this tip: see discussion for more information
Latest revision as of 10:39, January 31, 2014
Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).
Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
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") )