Vim Error: E474: Invalid argument: listchars=tab:»·,trail:·
Asked Answered
S

6

55

Summary:

I am receiving the following error for having the below line in my .vimrc file

Error:

E474: Invalid argument: listchars=tab:»·,trail:·

.vimrc:

set list listchars=tab:»·,trail:·

I have researched this and it appears to have something to do with UTF-8 encoding being properly set.

System Setup:

lsb_release:

Distributor ID: Ubuntu
Description:    Ubuntu 12.04 LTS
Release:        12.04
Codename:       precise

Locale:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=en_US
Stream answered 19/8, 2013 at 19:25 Comment(3)
Related: superuser.com/questions/556915/…Southwestwards
That locale setup doesn't make much sense. You have $LANG set to en_US.UTF-8, but then you override it for everything and even set $LC_ALL which will override the other $LC_* variables.Directoire
Mabey locale.conf is not right: LC_ALL=en_US.UTF-8 locale > /etc/locale.confPolonium
S
110

Solution:

Place the following lines at the top of the .vimrc the error mentions:

.vimrc:

scriptencoding utf-8
set encoding=utf-8
Stream answered 19/8, 2013 at 19:25 Comment(1)
Thanks for this. However, :h scriptsncoding says that: _If you set the encoding option in your .vimrc, :scriptencoding must be placed after that. Should these two lines be the other way around?Nutation
N
24

None of the other solutions worked for me.

My listchars looks like this:

listchars=eol:~,tab:>.,trail:~,extends:>,precedes:<,space:_

The problem was that my Vim is too old for the space: parameter in listchars. As we can read in this post (I modified the quote to make it more readable):

space: was added to listchars in v7.4.710 on 2015-04-21 by Bram. The stock Debian install of Vim doesn't offer space:.

The removal of the trailing ,space:_ solves the problem.


But wait! I want my vimrc to be portable

Well, as 816-8055 suggests you might use if has() in your vimrc:

if has("patch-7.4.710")
    listchars=eol:~,tab:>.,trail:~,extends:>,precedes:<,space:_
else
    listchars=eol:~,tab:>.,trail:~,extends:>,precedes:<
endif
Nacelle answered 2/4, 2016 at 14:1 Comment(1)
Thanks, that fixed it for me. I'm now using if has("patch-7.4.710") in my .vimrc because I have different versions on different systems.Zonnya
N
8

Just placing set encoding=utf8 anywhere in my _vimrc, but before set lcs=tab:>-,trail:·,nbsp:·,extends:>,precedes:< solved it

Nolanolan answered 5/9, 2018 at 4:58 Comment(1)
This worked for me, but only after I spelled encoding properly ;)Choke
T
6

Not a real solution to your specific problem, but another (non-utf8-safe) way might be just to use ASCII chars, like this:

set listchars=tab:>-,trail:.,precedes:<,extends:>

If you have UTF-8 available, Justins solution is the better one of course.

Tutankhamen answered 2/5, 2014 at 12:42 Comment(1)
Nice, but this only lets me see that it doesn't work here. Then I realised that set list is needed somewhere before this line.Massy
M
1

The tab character should be of the form XY i.e. two characters. Answered here.

Morgue answered 13/1, 2021 at 7:31 Comment(1)
In OP's example, it already is: X='»' and Y='·'Leeleeann
D
0

This isn't the problem here, but may help others with the same error: if your values include a space, you must escape it so vim doesn't parse the list as separate arguments.

:set listchars=tab:>\ ,trail:~,...
Desirable answered 10/5, 2022 at 16:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.