Using tmux with both emacs and vim

16

4

What is the best default key binding for tmux and why if one sometimes uses emacs and sometimes uses vim (on Linux Mint 12)? Ctrl-b is OK, but that conflicts a bit with the bash shell and emacs.

justingordon

Posted 2012-01-25T06:28:36.903

Reputation: 1 073

One that makes sense to you. Duh? – Ярослав Рахматуллин – 2015-09-24T04:13:26.057

Answers

9

I found a good answer in a related post: What's the least conflicting prefix/escape sequence for screen or tmux?

And I've gone with Ctrl-\. Below is my ~/.tmux-conf:

set-window-option -g mode-keys vi
set-window-option -g window-status-current-bg blue
set-window-option -g automatic-rename on
set-option -g status-keys vi
set-option -g history-limit 100000
set-option -g base-index 1
set-option -s escape-time 0
setw -g mode-mouse on
set-option -g mouse-select-pane on

# We won't worry about sending C-\ to any programs
# bind-key C-\ send-prefix

# hit C-\ twice to go to last window
bind-key C-\ last-window
bind-key b set-option status

bind-key / command-prompt "split-window 'exec man %%'"
# vim's definition of a horizontal/vertical split is reversed from tmux's
bind s split-window -v
bind v split-window -h

# move around panes with hjkl, as one would in vim after pressing ctrl-w
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# resize panes like vim
bind < resize-pane -L 10
bind > resize-pane -R 10
bind - resize-pane -D 10
bind + resize-pane -U 10

# C-b is not acceptable, due to emacs, bash, and vim
unbind-key C-b
set-option -g prefix C-\

justingordon

Posted 2012-01-25T06:28:36.903

Reputation: 1 073

This doesn't work out of the box for Mac. I went back to Ctrl-a, and switched to vim bindings and evil-mode for emacs, so I don't hit ctrl-a anymore for beginning of line. – justingordon – 2013-01-23T05:57:22.660

4

I strongly prefer C-], which doesn't conflict with vi bindings, and conflicts with the default abort-recursive-edit binding in Emacs. I use that rarely enough, and in nasty enough circumstances, that typing it twice isn't a big drama.

Daniel Pittman

Posted 2012-01-25T06:28:36.903

Reputation: 3 510

1

I have been using Ctrl-/ for a while and haven't found to conflict with anything at least in vim/bash. I don't use emacs so I don't know if it conflicts with anything important in it.

Also a small note I believe I had to bind it to C-_ to get it to work since that is the actual key it sends.

Neg_EV

Posted 2012-01-25T06:28:36.903

Reputation: 575

C-\ and C-_ are definitely different characters; respectively, they are 0x1C “File Separator” and 0x1F “Unit Separator”. See the table in Wikipedia’s ASCII control characters.

– Chris Johnsen – 2012-01-26T03:26:45.770

1

I chose Ctrl+Alt+b, i.e.

unbind C-b
set -g prefix M-C-b

Andrew

Posted 2012-01-25T06:28:36.903

Reputation: 232

1

I use C-\. Note that you need to escape it with single quotes:

unbind-key C-b
set-option -g prefix C-'\'

mahdix

Posted 2012-01-25T06:28:36.903

Reputation: 253

As a note, this conflicts with vim's evaluate expression shortcut key. – mahdix – 2015-09-30T09:18:44.220

0

The best solution I've come across for this is using just `. The only place this causes me problems is pasting in code directly (with system buffers), otherwise it's the perfect solution.

set -g prefix `
bind-key ` send-prefix

huntar

Posted 2012-01-25T06:28:36.903

Reputation: 121

0

Another good idea is to go for M-F3. It doesn't conflict with emacs and vi, the combinaison is rather convenient, is it' rather closed to the M-F2 and M-F1 used for run command and virtualdesktops menu.

[I'm using emacs, and starting some vim (inside emacs for now) and using linuxMint cinnamon for distro]

AdrieanKhisbe

Posted 2012-01-25T06:28:36.903

Reputation: 659