A case against C-a in tmux
tl;dr
Use C-o as your prefix in tmux instead of C-a, because C-a allows you to move your cursor to the beginning of the line. Read on if you don't understand what I mean.
I've heard it said that the C-a prefix is one of the things gnu screen "got right." Usually this is said during a conversation about changing the default configuration of tmux, which uses C-b as the prefix. Here's a quick explanation and why I disagree.
Anyone who does any amount of typing knows that B is one of the "inconvenient" keys. Take a quick look at the B key on your keyboard. Two issues should stand out: 1) it's the furthest letter key from your fingers, and 2) it sits an equal distance from each of your index fingers. Issue #2 will stand out if you strike the B key with your right index finger and have worked on a split keyboard. This is because split keyboards put the B key with the left hand. These issues combine to make C-b a poor choice for a prefix, but what about C-a? First, a quick digression.
I program in vim, but let’s talk about emacs. We spend a lot of time manipulating text. Our editors like vim and emacs do everything they can to allow us to do our text manipulations at or near home row. What a lot of people don’t realize is that the important text manipulation techniques from emacs are available in every textfield you interact with (except those in the Adobe Flash Player.) Here are a few key combinations I use multiple times a minute:
- C-f Move cursor forward one character
- C-b Move cursor backward one character
- C-n Move cursor down one line
- C-p Move cursor up one line
- C-k Kill all characters to the right of the cursor on the same line
- C-y Put whatever was killed last where the cursor is
- C-d Kill character to right of cursor
- C-h Kill character to left of cursor
- C-e Move cursor to the end of a line
- C-a Move cursor to the beginning of a line
Look at that last one. Anywhere that you are typing text you can strike C-a (control+a) to quickly move the cursor to the beginning of the line. Even when you're typing at a terminal. Give it a try. Open a terminal, type some text (without tmux open), and strike C-a to move the cursor to the beginning of the line. All of this works in instant messengers, browser address bars, word processors, html forms, etc.
Now, if you remap tmux from C-b to C-a you can no longer use C-a to move to the beginning of a line. But what else can you do? I use C-o as my tmux prefix. It's just as convenient as C-a! Try it and let me know what you think.
set -g prefix C-o
Written by Michael
Related protips
3 Responses
So the trick to being able to use C-a as "home" while still having C-a as your tmux prefix is to hit the sequence "C-a, a" (that's, hold 'control', tap 'a', release both, then tap 'a' again).
It's an extra keystroke, and requires some coordination to avoid hitting the other tmux keybinding to switch to the next pane (C-a-a, "hold 'control' and tap 'a' twice, then release), but at least keeps most of the tmux operations to the left hand, eg. new pane (C-a, c), kill pane (C-a, x), switch pane (C-a, q, <pane number>)
@ruiwen This is an option, yes, and I should've mentioned it. I still prefer not using C-a because it's a combination I use so often. C-o doesn't feel uncomfortable at all and it's used far less. In fact, the only time I use C-o is when I'm running a single normal mode command from insert mode in vim. Thanks for the input.
Not sure what your shell is, but the home key still goes to the beginning of the line in bash.