How to let vim listchar work under not utf8 environment?

8

1

My .vimrc contains:

if $LANG =~ '\(UTF\|utf\)-\?8' || $LC_CTYPE =~ '\(UTF\|utf\)-\?8'
  set list listchars=tab:»·,trail:~,extends:>,precedes:<
endif

But there is some chars which is unicode, when I run vim under LC_CTYPE=zh_TW.Big5 environment, it will show

Error detected while processing /home/user/.vimrc:
  line   70:
E474: Invalid argument: listchars=tab:»·,trail:~,extends:>,precedes:<

Daniel YC Lin

Posted 2013-02-25T03:25:34.173

Reputation: 795

Answers

5

Add the following line to your vimrc, preferably near the beginning:

scriptencoding utf-8

That will tell vim to read the file as UTF8 even if you're on a non-UTF system. It will then transcode any characters from that into your current encoding. If the characters you're using in the listchars option exist the other encodings that you use you shouldn't even need to have the conditional around that.

qqx

Posted 2013-02-25T03:25:34.173

Reputation: 2 603

This method works on vim, but, I found gvim still shows that error message. – Daniel YC Lin – 2013-02-25T05:11:17.007

Do you have a .gvimrc file that also contains unicode characters? If so, adding the same line to that file should fix the problem there as well. That command only applies to the file in which it is found, so would need to be included in any vim configuration file where the character encoding is important. – qqx – 2013-02-25T15:39:56.363

I found the problem caused by my gvimrc and fixed it. – Daniel YC Lin – 2013-02-27T01:23:48.077