What are the common Control combinations in a terminal setting

8

5

I would like to have a good guide to the common Control key combinations in use in bash (and similar) shells and the combinations used by common programs in use in those shells.

My particular motivation is to be able to run GNU screen on one computer, ssh to a second computer and use screen and irssi on that computer. So I need to use something other than Ctrl-A to control one of the screen sessions. So I need to know what are Control key combinations are safe to use.

But I imagine this list would be useful for others who want to bind custom actions to Control key combinations.

I reckon we'd be best to group the Control key combinations by application (eg. bash itself, screen, vim, emacs), to make it easy to spot the applications you use or can ignore. So please one application per answer - hope that works.

Hamish Downer

Posted 2010-03-15T22:45:47.843

Reputation: 3 064

2To address your particular motivation, I would discourage running screen-within-screen if you can avoid it: why do you want to use screen to maintain an ssh connection to another screen session? The point of screen is to allow ssh to close without losing your active program. I would suggest to just ssh to the second computer in a separate terminal.

If you do have to do it (I have done so in the past), I find there is actually less cognitive load if I simply leave the default key bindings alone. You're forced to be conscious of when you're in the inner screen anyway. – Zac Thompson – 2010-03-20T18:52:47.340

Answers

7

Bash itself uses the GNU readline library, as do many other interactive command-line programs. Readline has the following default key bindings which mimic emacs behaviour:

Moving about on the line:

  • Ctrl + A Go to the beginning of the line you are currently typing on
  • Ctrl + E Go to the end of the line you are currently typing on

Editing text on the line:

  • Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
  • Ctrl + H Same as backspace
  • Ctrl + W Delete the word before the cursor
  • Ctrl + K Clear the line after the cursor
  • Ctrl + T Swap the last two characters before the cursor
  • Esc + T Swap the last two words before the cursor

Other:

  • Ctrl + L Clears the Screen, similar to the clear command
  • Ctrl + R Let’s you search through previously used commands
  • Ctrl + C Kill whatever you are running
  • Ctrl + D Exit the current shell
  • Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.

Hamish Downer

Posted 2010-03-15T22:45:47.843

Reputation: 3 064

4These are for the emacs (set -o emacs) key bindings (bind -p). They would be different for vi (set -o vi) key bindings. – Paused until further notice. – 2010-03-16T00:39:30.290

@Dennis yes, but the keys are actually determined by the readline library, which lots of programs use. Bash has 'set -o vi' but other programs don't. So even if bash is used with vi keys, these would still conflict with other programs. I updated this answer and added one for emacs. – Zac Thompson – 2010-03-20T18:44:52.473

@Zac: But you can set editing-mode vi in an inputrc file. – Paused until further notice. – 2010-03-20T19:11:39.433

1

Vim uses:

  • Ctrl-B back (up) one screen
  • Ctrl-D down half screen
  • Ctrl-E scroll text up (cursor doesn't move unless it has to)
  • Ctrl-F foreward (down) one screen
  • Ctrl-G show status
  • Ctrl-H backspace
  • Ctrl-J line down
  • Ctrl-L refresh screen
  • Ctrl-N move down one line (or scroll forward through autocompletions)
  • Ctrl-P move up one line (or scroll backward through autocompletions)
  • Ctrl-R redo (after undo)
  • Ctrl-T go to the file/code you were editing before the last tag jump
  • Ctrl-U up half screen
  • Ctrl-V enter visual block mode
  • Ctrl-W used for managing split windows
  • Ctrl-Y scroll text down (cursor doesn't move unless it has to)

Hamish Downer

Posted 2010-03-15T22:45:47.843

Reputation: 3 064

1

Emacs uses everything. From http://www.cs.rutgers.edu/LCSR-Computing/some-docs/emacs-chart.html :

  • C-SP set-mark-command
  • C-a beginning-of-line
  • C-b backward-char
  • C-c exit-recursive-edit
  • C-d delete-char
  • C-e end-of-line
  • C-f forward-char
  • C-g (not explicitly mentioned in the link above, but used as a 'cancel' when entering commands)
  • C-h help-command
  • C-i (TAB) indent-for-tab-command
  • C-j (LFD) newline-and-indent
  • C-k kill-line
  • C-l recenter
  • C-m (RET) newline
  • C-n next-line
  • C-o open-line
  • C-p previous-line
  • C-q quoted-insert
  • C-r isearch-backward
  • C-s isearch-forward
  • C-t transpose-chars
  • C-u universal-argument
  • C-v scroll-up
  • C-w kill-region
  • C-x Control-X-prefix
  • C-y yank
  • C-z suspend-emacs
  • C-] abort-recursive-edit
  • C-_ undo

Zac Thompson

Posted 2010-03-15T22:45:47.843

Reputation: 887

1

It seems that Ctrl+Q would be an ideal escape key for GNU screen, is there a reason that nobody seems to suggest it?

The only downside I can think of is that on Mac OS X Command+Q is the keyboard shortcut for quitting an application which would be slightly dangerous if confused with Ctrl+Q.

Otherwise, from the current answers and my own research it seems that nothing conflicts with Ctrl+Q.

Han

Posted 2010-03-15T22:45:47.843

Reputation: 101

1Your terminals stop and start features are usually controlled by C-s and C-q, but its not very common (correct me if I am wrong) that people use this at all since its way easier to pipe into less, more or other processing tools. I'd safely say that you can rebind C-q without much hazzle. In my shells I always change the stty settings for start and stop to avoid pausing output unintentionally, I do this with: stty start '' stop '' in my bash startup scripts. – Mattias Ahnberg – 2012-01-07T02:20:41.370

FYI: When using PuTTY, If you accidentally hit Ctrl+s (XOFF) you need Ctrl+q to get your session responding again. – Dave Forgac – 2012-05-24T14:49:40.717

1

Lots of application uses the GNU readline library, so those keybindings are good to know about. You can study them in the readline(2) manual page, easily viewed here:
http://linux.die.net/man/3/readline

Mattias Ahnberg

Posted 2010-03-15T22:45:47.843

Reputation: 938

0

GNU screen by default uses Ctrl-A as its command key.

Hamish Downer

Posted 2010-03-15T22:45:47.843

Reputation: 3 064

2To use the Bash emacs-mode Ctrl-A (beginning-of-line) while running screen, press Ctrl-A followed by A (or press Home). – Paused until further notice. – 2010-03-16T00:43:21.663