1

I have file test.py with content:

print u'\u0410'

and Makefile:

test:
    python test.py

When I write in Vim :!python test.py I get

А

Press ENTER or type command to continue

But when I write :make test I get

python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    print u'\u0410'
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0410' in position 0: ordinal not in range(128)
make: *** [test] Error 1

Press ENTER or type command to continue

make test in terminal is ok.

Anyone have any ideas why it is could be so? Could you reproduce? Or is it only something with my setup?

Bunyk
  • 7,635
  • 8
  • 47
  • 79
  • I can reproduce it. I don't know why this is happening. But the reason it works differently in the shell is `:make test` is calling make through vim's internal commands. (So vim could be screwing something up). This is different from `:!make test` which runs make in the shell. (Notice the `!`). Seems to be the same problem as this http://stackoverflow.com/questions/20923663/unicodeencodeerror-ascii-codec-cant-encode-character-in-position-0-ordinal – FDinoff Mar 16 '14 at 20:51
  • Using `PYTHONIOENCODING=utf-8 python test.py` in the makefile fixes the problem. This was taken from the answer in the previously linked question. – FDinoff Mar 16 '14 at 21:03

1 Answers1

0

Change:

print u'\u0410'

to:

print u'\u0410'.encode('utf-8')

What's happening here is that vim adds 2>&1 | tee (from the shellpipe setting) after make (which is set from the makeprg setting). So your test.py script is in effect being redirected. Try running $ test.py > /tmp/foo and you'll get the same error. Solution: encode your output to a reasonable encoding, like utf-8.

Louis
  • 146,715
  • 28
  • 274
  • 320