Setting up UTF-8 and getting home/end & word movement to work in Terminal.app, Tiger

While I know there are a ton of these available on the web already, I've not found anyone covering both setting up UTF-8 and getting Home/End working properly (as in, jumping to the beginning of a line and to the end of a line, instead of scrolling to the beginning and end of the buffer, which for some reason Apple thought was brilliant). I'm also going to cover how to get word movement (ctrl+arrow left/right) working, as well as getting backspace and forward delete functional.. This was all tested and is fully working even with SSH and GNU/Screen running. I'm using OS X 10.4.11 Tiger.

UTF-8 Support

Getting UTF-8 to work is quite simple. Fire up Terminal.app, and press cmd-I to bring up the Window Inspector. From the drop-down list, choose Emulation and turn off the option named Escape non-ASCII characters.

Next up is the Display-section in the drop-down list. Choose Unicode (UTF-8) as your Character Set Encoding.

Important! Remember to choose Use Settings as Defaults at the bottom of the Inspector to make sure your settings are saved.

Almost done! There's only one more thing to do. Fire up your favourite editor (mine's TextMate!) and open (or create, if it doesn't exist) ~/.profile, and add the following:
export LC_CTYPE=en_US.UTF-8

Next, open/create the file ~/.inputrc, and add the following:
set meta-flag on
set input-meta on
set output-meta on
set convert-meta off

Close the Terminal window and reopen it (cmd-W, cmd-N). UTF-8 should now be working fine. Note that if you run SSH and GNU/Screen, make sure you turn on Unicode (start it with the -U flag, also remember to add this when resuming as well).

Getting backspace and forward delete working

The first thing you need to do is in the Keyboard-section chosen from the drop-down list, in Window Inspector (brought up by cmd-I when Terminal.app is open). Here, all you need to do is make sure the option called Delete key sends backspace is checked (enabled).

You also need to edit the Key Mapping for del (forward delete), by choosing it and selecting Edit. In the text field, hit Escape, which should make it show \033 in the field. Then add [3~ after it, so it looks like this:

Like before, remember to click Use Settings as Default!

Next, open or create ~/.profile, and add the following:
stty erase ^H

Restart Terminal.app (or close the window and open a new one using cmd-W, cmd-N), or just write source ~/.profile.

Getting Home/End and word movement working correctly

This one is quite easy as well. It doesn't even require you to edit any files. Open up Window Inspector (cmd-I) within Terminal.app. Go to the Keyboard-section from the drop-down list. What we need to do is similar to making forward delete work in the section above. Scroll down on the list until you find home, select it, and choose Edit. In the Action-drop down, select send string to shell:, hit Escape and write [1~ immediately after it. It should now look like this:

The rest of the procedure is the same as this, except that you have to write different codes (and select send string to shell: for atleast one of the entries:
Key: end - Action: \033[4~
Key: control cursor left - Action: \033b
Key: control cursor right - Action: \033f

Select Use Settings as Default, and your keys should now be working, including word movement (jumping one word at a time).

That should be it! If you have any suggestions/corrections, notify me by mail or in the comment field and I'll update as necessary.
I don't remember where I found all of this (repeatedly googling over and over, heh), but the UTF-8 stuff was taken from macosxhints.com - A guide to help set up Terminal, a generally great site for hints and tips.

Hope this helps someone!

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Captcha Image: you will need to recognize the text in it.
Please type in the letters/numbers that are shown in the image above.