Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Please undelete you answer and when you can, accept it rather than editing your original question. –  Iain Sep 1 '11 at 7:25
    
It turns out it wasn't a complete answer. I've updated my original question :-) –  Hubro Sep 1 '11 at 7:57
add comment

2 Answers 2

up vote 6 down vote accepted

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).

share|improve this answer
    
I still can't input symbols æ, ø or å. There was no file ~/.inputrc so I created it and put set input-meta on in it. I started a new session, but still couldn't put the symbols in. –  Hubro Sep 3 '11 at 12:12
    
@Codemonkey: Hm, weird. Did you try input after starting a program like vim on the remote server? Did that work? I'm afraid I can't really help much beyond that. Maybe try asking on the chat. –  sleske Sep 3 '11 at 19:17
    
No, didn't work :( –  Hubro Sep 4 '11 at 11:07
add comment

Okay, so I'm having the same problem trying to input non-ASCII characters into Putty on a Debian-based system (Ubuntu Server). My fix works completely and is as follows:

1) Changed character set to UTF-8 in Putty under Settings->Window->Translation
2) Confirmed that $LANG environment variable is set to en_us.UTF-8 on the server
3) Created ~/.inputrc with the following options:

set input-meta on
set output-meta on
set convert-meta off 
set enable-meta-key on

4) Log out, log back in (not sure if this is necessary)
5) Now I can copy/paste non-ASCII chars into the terminal and I can successfully use the meta key to manually type in chars like: ƒ,å,Ü...

Please see the following 'manpage' which describes the options that I used in step 3 in more detail: http://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html

Hope this helps somebody. Cheers.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.