Resolving ;5D Terminal Control Sequence Issue When Using Ctrl+Arrow Keys in FreeBSD SSH Session


1 views

Many Linux users are familiar with the handy Ctrl+Arrow key combination for word navigation in terminal sessions. When connecting to FreeBSD systems via SSH from Linux clients (particularly Ubuntu with Terminator), you might encounter this behavior:

$ tail -f application.log;5D;5D;5D

Each Ctrl+Arrow keypress generates the ;5D control sequence instead of moving between words.

The root cause lies in how different terminal emulators handle special key combinations:

  • Linux terminals typically send \033[1;5D (left) or \033[1;5C (right)
  • FreeBSD's default shell (tcsh) interprets these sequences differently
  • Terminator specifically has known variations in escape sequence handling

For bash users (if installed on FreeBSD), add this to your ~/.inputrc:

# Ctrl+left/right arrow word navigation
"\e[1;5D": backward-word
"\e[1;5C": forward-word
"\e[5D": backward-word
"\e[5C": forward-word

Then reload with:

bind -f ~/.inputrc

In Terminator's preferences (right-click > Preferences):

  1. Go to Profiles tab
  2. Select your current profile
  3. Under Compatibility, set "Backspace key" to Control-H
  4. Check "Override XTerm resources"

If you prefer not to modify configurations, try these alternatives:

  • Ctrl+b / Ctrl+f (back/forward by character)
  • Esc+b / Esc+f (back/forward by word)
  • Alt+b / Alt+f (works in most default configurations)

After making changes, test with:

# Type this then try Ctrl+arrows
$ echo "test string with multiple words"

The cursor should now move word-by-word instead of displaying control sequences.


When working with FreeBSD systems through SSH from a Linux client (like Ubuntu with Terminator), you might encounter an annoying behavior where pressing Ctrl+arrow keys produces ;5D sequences instead of moving between words. This happens because:

$ tail -f logfile.log;5D;5D;5D

Different terminals and shells handle control sequences differently. The Linux-style word navigation (Ctrl+arrow) uses different escape sequences than BSD systems expect. The ;5D you're seeing is actually:

  • ; - separator
  • 5 - control modifier
  • D - right arrow key code

For bash users, add this to your ~/.inputrc:

"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word

For tcsh users, modify ~/.cshrc:

bindkey "\e[1;5C" forward-word
bindkey "\e[1;5D" backward-word

If you prefer using Alt/Meta instead of Ctrl:

# For bash
"\e[1;3C": forward-word
"\e[1;3D": backward-word

# For tcsh
bindkey "\e[1;3C" forward-word
bindkey "\e[1;3D" backward-word

After making changes, either restart your shell or source the configuration:

# For bash
source ~/.inputrc

# For tcsh
source ~/.cshrc

Now test with Ctrl+left/right arrows - the cursor should move by words instead of printing escape sequences.

To make this system-wide (requires root access):

# For bash
sudo echo '"\e[1;5C": forward-word' >> /etc/inputrc
sudo echo '"\e[1;5D": backward-word' >> /etc/inputrc

# For tcsh
sudo echo 'bindkey "\e[1;5C" forward-word' >> /etc/csh.cshrc
sudo echo 'bindkey "\e[1;5D" backward-word' >> /etc/csh.cshrc