3

I have a problem editing a html file on a server via vim. The file is utf-8 encoded.

While editing with vim (v7.3, no plugins active) I can see umlauts and editing and saving a line before the umlaut is ok. But if I edit after the umlaut it seems that the umlaut consumes two chars while only one char is visible and all edits are shifted. I can see this only after saving and reopening the file. And I can insert an umlaut but for removing I have to press x twice (the char changes meanwhile).

I have no idea where to search for the issue vim, terminal or ssh connection?

remote:

> file index.html
index.html: HTML document, UTF-8 Unicode text
> echo $TERM
xterm-256color
> locale charmap
ANSI_X3.4-1968
> grep CHARMAP /etc/default/console-setup 
CHARMAP="UTF-8"

local:

> locale charmap
UTF-8
Knut
  • 201
  • 2
    vim has various encoding settings; what do :set encoding and :set fileencoding say when the file is loaded? Read the vim help for details. – Murphy Apr 11 '16 at 11:24
  • 1
    It also looks as if your environment were not UTF-8 clear. What does locale charmap (both local and at the remote end) say? What OS are you using? – Radovan Garabík Apr 11 '16 at 12:10
  • OS is Linux. vim settings after open file: encoding=latin1, fileencoding= – Knut Apr 11 '16 at 12:20
  • If I copy (scp) the file to my local machine, encoding and fileencoding in vim is both utf-8. Somehow vim on remote does not recognize the encoding... – Knut Apr 11 '16 at 12:28
  • Check if the vim encoding set manually somewhere, e. g. in ~/.vimrc or /etc/vim/vimrc. What do local and echo $LANG display on the remote host? – Murphy Apr 11 '16 at 12:44

1 Answers1

3

It turns out, that the terminal locales were setup somehow wrong. My .bashrc had a export LC_ALL=C.

> locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
...
LC_IDENTIFICATION="C"
LC_ALL=C

After removing LC_ALL=C I get this:

> locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_GB.UTF-8
...
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=

Vim now opens the same file with enconding=utf-8 and fileencondig=utf-8 and editing is normal.

Thanks Murphy and Radovan for some pointers. Maybe anyone has an explanation for this issue.

Knut
  • 201
  • 2
    LC_ALL="C" was disabling all the language locales defined and it is useful by it´s own when debugging locales problems. see 2nd answer in http://unix.stackexchange.com/questions/87745/what-does-lc-all-c-do – Rui F Ribeiro Apr 11 '16 at 13:07
  • 1
    In my case /etc/locale.gen didn't have my international locale described. Uncommented the right line, then re-ran locale-gen, everything works. – lkraav Dec 14 '16 at 19:43