Home » Questions » Computers [ Ask a new question ]

How to configure PuTTY so that Home/End/PgUp/PgDn work properly in bash?

How to configure PuTTY so that Home/End/PgUp/PgDn work properly in bash?

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?

Asked by: Guest | Views: 148
Total answers/comments: 5
bert [Entry]

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

"If you want to verify which code is sent by PuTTY to your terminal when you press a key or a combination of keys, you just have to issue a Ctrl+V and then press on the desired key.

For example on my box, pressing the Home key will generate the following string on my terminal:

^[[1~

That means that PuTTY sends the escape character ^[ followed by the string [1~.

You can create an ~/.inputrc file in your $HOME folder, or alternatively an /etc/inputrc file depending on your system. Then fill this file with the PuTTY codes and the matching Bash actions you want to be triggered by Bash.

Note: Replace every ^[ character by the equivalent \e string

In my example, I'll add a line with my Home key code and the beginning-of-line action (which by default is bound to Ctrl+A in Bash):

""\e[1~"": beginning-of-line

FYI, my inputrc file has the following content:

set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
""\e[1~"": beginning-of-line # Home key
""\e[4~"": end-of-line # End key
""\e[5~"": beginning-of-history # PageUp key
""\e[6~"": end-of-history # PageDown key
""\e[3~"": delete-char # Delete key
""\e[2~"": quoted-insert # Insert key
""\eOD"": backward-word # Ctrl + Left Arrow key
""\eOC"": forward-word # Ctrl + Right Arrow key

From @Cimbali: More bindable commands (like previous-history: Move `up' through the history list) available on this reference page."
bert [Entry]

"Non of these options worked for me. I am running an old AIX system. I had to add the following alias's to my .profile

alias __A=$(print '\0020') # ^P = up = previous command
alias __B=$(print '\0016') # ^N = down = next command
alias __C=$(print '\0006') # ^F = right = forward a character
alias __D=$(print '\0002') # ^B = left = back a character"
"Non of these options worked for me. I am running an old AIX system. I had to add the following alias's to my .profile

alias __A=$(print '\0020') # ^P = up = previous command
alias __B=$(print '\0016') # ^N = down = next command
alias __C=$(print '\0006') # ^F = right = forward a character
alias __D=$(print '\0002') # ^B = left = back a character"
bert [Entry]

"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."
bert [Entry]

"For MTPuTTY

Open any connection properties
Click Run PuTTY Config
Open Connection > Data tab and set Terminal-type string to linux
Come back to Session tab
Select Default Settings in the list and click Save
Close the window"