Linux – How to enable characters like [Æ, Ø, Å] in PuTTY/Debian

debianencodinglinuxputtyvim

I'm using VIM through PuTTY to work on my development server, but it gets rather difficult when I have to work on files containing characters like those mentioned in the title. Not only does it make VIM look like this

Denne applikasjonen krever at Javascript er aktivert.
Bruk en nettleser som støtter JavaScript eller aktiver JavaScript i din nåværende nettleser.

But also it completely f*cks VIM up, making the visual caret sitting somewhere completely random relative to where text appears when I'm typing.

The files I'm editing uses ISO-8859-1 encoding

root@foo:~/www/pltest# file --mime-encoding index.php
index.php: iso-8859-1

And PuTTY is set to expect ISO-8859-1 in Settings->Window->Translation. So the only issue can be Debian. If I try typing any of the above characters into the console, random appears:

root@foo:~/www/pltest# ���������

Any idea how I can get Debian to allow ISO-8859-1 symbols?


Solved it (Partly)! Apparently displaying the symbols was as simple as printing out /etc/locale.alias, finding my locale in the list and setting the corresponding language code (in my case nb_NO.ISO-8859-1) to the LANG environment variable. However, I'm still not able to type the characters into the PuTTY window. Any time I try I hear a windows error 'ding'.

Any ideas?

Best Answer

In order for non-ASCII characters to work, all the programs involved must use the same character encoding. The encoding needs to be set:

  • 1) in Putty (you have done that)
  • 2) on the remote system (usually by setting the LANG env variable to a suitable locale)

Then using non-ASCII on the console should work.

The settings for vim are (mostly) independent of this. vim has its own internal setting for the encoding of the files it edits, and will automatically re-encode text to be suitable for the system settings (i.e. the locale set using LANG).

To address your problem:

You have apparently taken care of 1) & 2), by setting the same encoding in Putty and using LANG. Now editing a file with non-ASCII characters should work in vim, provided vim knows which encoding the file has (either by autodetection, or by doing a :set fileencoding=UTF-8 etc. in vim).

As to "getting a ding when typing non-ASCII characters": You might need to put set input-meta on into your ~/.inputrc (this tells the readline library and thus bash that you want to type non-ASCII stuff) - but most modern Linux distros should no longer need this.

Try to see whether other programs like vim accept non-ASCII stuff - that should tell us where the problem is.

A final remark:

While setting the locale to use ISO 8859-1 certainly works, it is usually better in the long term to use UTF-8. UTF-8 works for just about any language, not just western languages, and is quickly becoming the standard on modern Linux distros.

Note that you can still work with ISO-encoded files in vim, as vim can transcode automatically (it will often even auto-detect that the file is not in UTF-8).