38

When I am connected to my local Ubuntu dev server with putty (from my Windows 7 box) via SSH, the following key combinations don't work to move the cursor forward and backward on word boundaries:

  • Ctrl+Left Arrow on the cursor pad
  • Ctrl+Right Arrow on the cursor pad

The cursor only moves one character at a time. I'm using bash.

phuclv
  • 26,555
  • 15
  • 113
  • 235
user26767
  • 591
  • 1
  • 7
  • 10
  • 2
    bash uses Emacs key bindings by default, so `Alt+B` and `Alt+F` will move backward/forward one word. You can change to vi bindings if you want and move by `w` – phuclv Jul 02 '18 at 02:19

2 Answers2

54

Add these two lines to your ~/.inputrc file on the destination machine:

"\eOD": backward-word
"\eOC": forward-word

To make sure that they are the correct sequences, at a Bash prompt, type Ctrl-V Ctrl-LeftArrow and Ctrl-V Ctrl-RightArrow, you should see:

^[OD^[OC

When you start a new session, the keys will be available or you can press Ctrl-xCtrl-r to re-read the ~/.inputrc file for the current session.

Dennis Williamson
  • 106,229
  • 19
  • 167
  • 187
  • Would a similar trick work for deleting whole words? – Casebash Nov 01 '11 at 04:00
  • @Casebash: Try `bind -P | grep kill-word` to show you the existing key bindings for deleting whole words. You can change the bindings in a similar manner to my answer above, if needed. – Dennis Williamson Nov 02 '11 at 15:46
  • I noticed that OpenSuSE (12.3) had bound these sequences already to `backward-char` and `forward-char`, so rather than just adding these lines, I had to replace the lines that already contained the bindings. – palswim Nov 01 '13 at 18:15
  • Great! Worked for Ubuntu 14.04 for me, and my putty is running on a Windows 7 box. – Edwin Yip May 01 '16 at 10:01
  • Doesn't work with Putty on win10 – nZeus Feb 22 '18 at 21:41
  • @nZeus: The character sequences may be different in your case. What do the `Ctrl` sequences output for you? – Dennis Williamson Feb 22 '18 at 22:49
  • It works now. I thought I should create this file on the client PC, but I just tried to do it on the server and now it works :+1: – nZeus Mar 06 '18 at 09:03
5

For the Linux console:

"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert

7.7. Creating the /etc/inputrc File

jcoffland
  • 369
  • 3
  • 8
Meetai.com
  • 721
  • 1
  • 6
  • 10