I just move from GNU screen to tmux, in screen when I hit C-a
, then type a
again can take me to the beginning of the line, I wonder if I stick with C-a
in tmux how can I work around this?
Asked
Active
Viewed 7.1k times
77

mko
- 21,334
- 49
- 130
- 191
-
1possible duplicate of [Howto go to beginning of line in tmux after remapping prefix to CTRL+A?](http://stackoverflow.com/questions/9684115/howto-go-to-beginning-of-line-in-tmux-after-remapping-prefix-to-ctrla) – Chris Johnsen Jul 20 '12 at 03:14
-
@ChrisJohnsen Thanks for point out this existing question, It also helps – mko Jul 20 '12 at 03:50
-
Possible duplicate of [Howto go to beginning of line in tmux after remapping prefix to CTRL+A?](http://stackoverflow.com/questions/9684115/howto-go-to-beginning-of-line-in-tmux-after-remapping-prefix-to-ctrla) – Nifle Jan 30 '17 at 09:47
-
[OPINION] While ctrl-a is undoubtedly easier to type on 'qwerty' keyboards than ctrl-b, I generally discourage people from customizing unix tools this way. If all you did was change tmux's 'prefix' key, it wouldn't be so bad. But often people aren't content to stop there, and they end up with such a severely customized tmux that they will be out of sorts if ever asked to use someone else's machine that follows the default behaviors. The best practice is, I feel, to adopt what standards already exist, and save customizations for your own extensions to functionality. – Cognitive Hazard Mar 14 '17 at 18:16
-
[ANOTHER OPINION] I suggest to use the `Ctrl-j` prefix for any terminal multiplexer since in both Emacs and Vim behave like the Enter key (as long as your Enter key works you should be fine); also `j` is in your home row; also the left `Ctrl` is usually closer than the right `Ctrl` so `Ctrl-j` it's a fast combination; also `j` looks like a hook. – isar Dec 03 '17 at 10:00
2 Answers
92
Maybe its an issue about the version I am using, but if the above code does not work for you, try this:
set -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix

user1978011
- 3,419
- 25
- 38
-
12Thanks, the `-g` is certainly required on my Ubuntu install, perhaps the op should confirm that the accepted answer still works for him? – stephenmurdoch Aug 26 '14 at 08:09
-
3
-
-
1The global mean "all sessions" - I had the same issue, with one session updated but the other not. -g saves the day. – Goblinhack Apr 22 '16 at 23:17
-
-
-
88
As you know, C-b
is the default prefix in tmux
. C-b C-b
is used to send an actual C-b
character to the terminal. If you switch the prefix to C-a
, you just need to rebind some keys to update which one sends the send-prefix
command.
For your .tmux.conf
:
# You probably already put this in
set prefix C-a
unbind-key C-b
bind-key C-a send-prefix

chepner
- 497,756
- 71
- 530
- 681
-
-
13After those keybindings are in place, `C-a C-a`. You can also add `bind-key a send-prefix` to keep the screen-like `C-a a` sequence. – chepner Jul 19 '12 at 16:02
-
Really could you show me the code? I know `bind-key C-a last-window` but I can't find `begin-of-line` in the man page of tmux – mko Jul 19 '12 at 21:06
-
5The point of `send-prefix` is that it sends the prefix key on to the shell. `tmux` doesn't move the cursor to the beginning of the line; `bash` does it (via `readline`) when it receives `C-a`. Trust me, the above code is what you want in your `.tmux.conf`. – chepner Jul 19 '12 at 21:20
-
1How stupid I am, I didn't completely quite the tmux session after change the configuration file, now it works thanks a lot ! – mko Jul 20 '12 at 03:49
-
11you can also do a `C-a :source ~/.tmux.conf` to reload the conf file without quiting your tmux session. – jackbravo Oct 27 '13 at 16:51
-
Or if you change your .tmux.conf settings a lot, you can rebind r (or any other key) to reload the configuration file, by adding these 2 lines to `~/.tmux.conf` file: `unbind r` and `bind r source-file ~/.tmux.conf; display "~/.tmux.conf Reloaded"` – galfisher May 15 '17 at 15:17