Using many control keys during the day, such as Ctrl-f to page down in Vim and Ctrl-c to kill a process in terminal, and assigning some of my own to tmux, I’ve began wondering whether all the letters of the alphabet were accounted for. The answer is: yes, they are; plus even some extra characters.
Most key bindings differ depending on the context, except ones in the “term” column that always keep the same function. The layers that I’m most interested in are:
- the shell (bash/zsh with Emacs key bindings), where I edit commands and browse history;
- process control while running a process attached to the terminal;
- Vim, which I use exclusively in the terminal.
I have compiled a comprehensive overview of all control key bindings in different contexts and highlighted the features that matter to me the most:
term | shell prompt | process | Vim normal | |
---|---|---|---|---|
C-A | start of line | increment number | ||
C-B | move back a char | page up | ||
C-C | SIGINT | |||
C-D | delete char | send EOF | half page down | |
C-E | end of line | scroll up | ||
C-F | move forward a char | page down | ||
C-G | abort line | file/position info | ||
C-H | <Bsp> | |||
C-I | <Tab> | jump forward | ||
C-J | <LF> | |||
C-K | kill text to end of line | |||
C-L | clear screen | |||
C-M | <CR> | |||
C-N | next history | move cursor down | ||
C-O | operate-and-get-next | jump back | ||
C-P | previous history | move cursor up | ||
C-Q | zsh: clear line | |||
C-R | backward inc. search | redo | ||
C-S | forward inc. search* | |||
C-T | transpose chars | SIGINFO | undo tag jump | |
C-U | clear line | half page up | ||
C-V | insert next char literally | visual block mode | ||
C-W | delete word | window prefix | ||
C-X | prefix, e.g. C-x,C-e | decrement number | ||
C-Y | yank | (delayed suspend) | scroll down | |
C-Z | SIGTSTP (suspend) | |||
C-\ | SIGQUIT | |||
C-[ | <Esc> | exit insert mode | ||
C-] | jump to tag | |||
C-^ | alternate buffer |
In the shell, these are indispensable:
- C-r - Backward incremental search through history
- C-s - Forward incremental search
*For bash, C-s
doesn’t work by default.
Here’s how to enable it:
# Allow <C-s> to pass through to shell and programs
stty -ixon -ixoff
For process control:
- C-z - Suspend a process. Useful for switching away from a man page or Vim while keeping the option to return to it intact.
- fg (shell) - Return a process to foreground
- jobs (shell) - List suspended processes
In Vim:
- C-f/b - Page down/up
- C-a/x - Increment/decrement the number after cursor. Can’t do CSS without it!
- C-] - Jump to tag under cursor
- C-o - Backtrack after having jumped
To learn more about navigating tags and jumps in Vim, see Vim: Revisited.