How to edit UTF-8 files with vim
How can I edit UTF-8 files with vim?
There is a problem with german special characters like 'Ä', 'ü'. There are some in the comments. vim shows Ã~D
instead of 'Ä' and ü
instead of 'ü' then. (I hope there is no encoding problem on your browser :)
I have no "~/.vimrc" file.
In the "~/.viminfo" is
...
# Value of 'encoding' when this file was written
*encoding=latin1
...
If I enter locale
, it gives LANG=C.UTF-8
. It was LANG=C
but I changed with export LANG=C.UTF-8
. But nothing changed.
I'm using MobaXterm 11.0 to get access from a Win10 computer. Maybe there is the problem?
(Linux v. "Ubuntu 18.04.4 LTS")
Update:
- MobaXterm was already (and still is) set to UTF-8
- I have changed with [CTRL] + right mouse key (then there is a menu) the shell to UTF-8.
- In addition I set
export LC_TYPE=de_DE.UTF-8
("de_DE"!)
Now it works a bit better :-|
- more and cat works
- less and vi not
With set enc:utf8
in vi, it works there. (So vi is a little part of the solution)
And about less
I should maybe read the manpages...?
If the encoding of the file is messed up you can let Vim now by entering these commands:
: set enc=utf8
: set fenc=utf8
The first command controls how the content is displayed, the second how it is written to disk.
However, the problem with wrong encoding could also be in a SSH-client like putty for instance, if you try to edit over SSH. If so have a look at Putty setting to get right encoding.