Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The keys Home, End, PageUp, PageDown all type a ~ in my bash session instead of moving the cursor / view around. Why does this happen and which settings do I need to change?

GNU bash, version 4.0.28(1)-release (x86_64--netbsd)
PuTTY v0.60

The question originally read:

In PuTTY, why does pressing the "Home" key on the shell (bash) type a "~"? Or rather, how do I make it move the cursor to the start of the command I've typed?

(I thought the reason was that ~ is the home directory, but the answers say this is not so.)

share|improve this question
add comment

5 Answers

up vote 42 down vote accepted

Change the Terminal-type String under the Connection > Data tab from the default “xterm” to “linux”. It worked for me.

share|improve this answer
    
Thanks! I had this problem after I tred to make Ctrl Left/Right work using this method (superuser.com/a/103097/45410). –  Edwin Yip Nov 4 '12 at 17:04
add comment

This is happening because you don't have PuTTY's terminal type set correctly, or because your server doesn't have the correct terminfo definitions installed.

On Debian-based systems, the ncurses-term package (version 5.7+20081213-1) includes terminfo definition files for putty, putty-256color and putty-vt100 terminal types. If you have this package installed, you can set the "Terminal-type string" to "putty" instead of the default "xterm" in Putty's session configuration (Connection -> Data).

Stephen Irons also mentions "linux" as another terminal type that works; I believe this is correct from prior experience, but haven't tested it recently.

On my systems, this allows Home and End to work correctly, though PageUp/PageDown do not scroll the console window. (They do work properly in ncurses applications like aptitude, and Shift-PgUp/Shift-PgDn scroll the console window.)

share|improve this answer
    
Yes, using TERM=putty or TERM=putty-256color is wisest, though unfortunately at the moment the latter doesn't seem to work right for colors 8-15 (which are supposed to be the bright versions of 0-7). The other "solutions" are are very likely to flake out sometimes do to their flagrant disregard of the differences between the terminals involved. –  SamB Oct 14 '10 at 21:05
add comment

What it's actually sending is ^[[1~ which is a terminal escape sequence consisting of:

  • ^[ - escape
  • [ - left square bracket
  • 1 - one
  • ~ - tilde

You can see that by pressing Ctrl+V then Home.

You might be able to fix your problem by changing the PuTTY keyboard setting for Home and End keys to rxvt (which makes the escape sequence ^[[H or by changing the $TERM you're using (or by editing ~/.inputrc).

By the way there's no relationship between the tilde you get when you press Home and the tilde that represents the home directory. For example, in my setup Page-Down produces ^[[6~ which would also print a tilde if it weren't being properly interpreted.

share|improve this answer
    
Thanks! rxvt fixed the Home key; the End key now produces a ding. PgUp/Down do indeed type ~, and none of the PuTTY Keyboard settings make them work. Is my bash messed up, or is this "normal"? –  romkyns Jan 11 '10 at 17:39
    
What do you get when you type echo $TERM? –  Dennis Williamson Jan 11 '10 at 18:07
    
xterm (15 character limit argh) –  romkyns Jan 11 '10 at 18:08
2  
You can try adding "\eOw": end-of-line (that's a capital letter O) to your ~/.inputrc file. –  Dennis Williamson Jan 11 '10 at 18:21
    
End key fixed; I get the idea. Really wish hacks like this weren't necessary though... –  romkyns Jan 11 '10 at 18:27
show 1 more comment

Crtl+A takes you to the start of the line

Here's a list of Bash keyboard shortcuts

share|improve this answer
4  
That's great and all, but Home/End are hard-wired in my brain, and since I only administer the server once in a blue moon the chances of unlearning the hard-wiring are slim. –  romkyns Jan 7 '11 at 12:27
add comment

I couldn't get it working with other methods. I however created this AutoHotkey script that works, as long as your shell is Bash:

#IfWinActive ahk_class PuTTY
PgUp::Send +{PgUp}
PgDn::Send +{PgDn}
Home::Send ^a   ; beginning of line
End::Send ^e    ; end of line
+^Del::Send ^k  ; delete whole line after cursor
+End::Send ^k   ; delete whole line after cursor
+Home::Send ^u  ; delete whole line before cursor
^Del::Send !d   ; delete word after cursor
^BS::Send ^w    ; delete word before cursor
^Left::Send !b  ; jump word left
^Right::Send !f ; jump word right
#IfWinActive

Use with caution though, since not all of these bash hotkeys work in other programs.

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.