Tmux for mere mortals

栏目: IT技术 · 发布时间: 4年前

内容简介:Tmux has liberated me from tiling window mangers. Not that I didn’t like those, but I occasionally have to work with macOS or default GNOME setups. And over the years I realised that I only need a terminal multiplexor to do terminal tiling for me, the rest

Tmux has liberated me from tiling window mangers. Not that I didn’t like those, but I occasionally have to work with macOS or default GNOME setups. And over the years I realised that I only need a terminal multiplexor to do terminal tiling for me, the rest of the windows are just fine to be full-screen in separate workspaces.

So, I ended up doing 80% of my work in terminals with tmux. But, the prefix thing? Pardonnez-moi, but usability matters. Pressing a chorded prefix hotkey only to press another chorded hotkey to perform a single action is clear nonsense.

With this in mind, I decided to customize my tmux to use only simple chorded hotkeys without a prefix for most common actions, and to make them easy to remember. Additionally, my goal was not to override anything in the default tmux configuration to be able to use default tmux as well, if I have to (i.e. when ssh’ed to some remote server). Finally, I wanted it to be similar in German/US keyboards, as well as work for MacBooks and regular laptops.

Here’s what I came up with:

Tmux for mere mortals

  • Mod+1..9: switch windows from 1 to 9
  • Mod+, and Mod+.: switch to next/prev windows
  • Mod+HJKL or arrows: switch between panes
  • Mod+N: create new window
  • Mod+F: toggle full-screen
  • Mod+V: split vertically
  • Mod+B: split horizontally (“bisect”)
  • Mod+X: close pane
  • Mod+/: enter copy and scroll mode

Intuitive? Now, same hotkeys with Shift key are used to modify things:

Tmux for mere mortals

  • Mod+< and Mod+>: move current window to the left/right
  • Mod+Shift+HJKL or arrows: move pane to the left/right/up/down
  • Mod+Shift+X: close window
  • Mod+Shift+R: rename window

That’s pretty much everything I ever needed from tmux. For other, less frequent actions I accept to use the default bindings, from time to time.

Additionally, I would like tmux to use my primary clipboard on all systems, so that I would only have to copy text with my mouse or keyboard selection. Resizing panes is also usable with a mouse.

As for the status bar, I’m not a big fan of being overloaded with information, so I only show window names there, or in the case then window has only an open shell - current directory name.

Nothing else.

Here’s the tmux.conf (or you may always have a look at my dotfiles for a newer version:

set-option -g default-terminal screen-256color
set -g history-limit 10000
set -g base-index 1
set-option -g renumber-windows on
set -s escape-time 0
bind-key -n M-n new-window -c "#{pane_current_path}"
bind-key -n M-1 select-window -t :1
bind-key -n M-2 select-window -t :2
bind-key -n M-3 select-window -t :3
bind-key -n M-4 select-window -t :4
bind-key -n M-5 select-window -t :5
bind-key -n M-6 select-window -t :6
bind-key -n M-7 select-window -t :7
bind-key -n M-8 select-window -t :8
bind-key -n M-9 select-window -t :9
bind-key -n M-0 select-window -t :0
bind-key -n M-. select-window -n
bind-key -n M-, select-window -p
bind-key -n M-< swap-window -t -1
bind-key -n M-> swap-window -t +1
bind-key -n M-X confirm-before "kill-window"
bind-key -n M-v split-window -h -c "#{pane_current_path}"
bind-key -n M-b split-window -v -c "#{pane_current_path}"
bind-key -n M-R command-prompt -I "" "rename-window '%%'"
bind-key -n M-f resize-pane -Z
bind-key -n M-h select-pane -L
bind-key -n M-l select-pane -R
bind-key -n M-k select-pane -U
bind-key -n M-j select-pane -D
bind-key -n M-Left select-pane -L
bind-key -n M-Right select-pane -R
bind-key -n M-Up select-pane -U
bind-key -n M-Down select-pane -D
bind-key -n "M-H" run-shell 'old=`tmux display -p "#{pane_index}"`; tmux select-pane -L; tmux swap-pane -t $old'
bind-key -n "M-J" run-shell 'old=`tmux display -p "#{pane_index}"`; tmux select-pane -D; tmux swap-pane -t $old'
bind-key -n "M-K" run-shell 'old=`tmux display -p "#{pane_index}"`; tmux select-pane -U; tmux swap-pane -t $old'
bind-key -n "M-L" run-shell 'old=`tmux display -p "#{pane_index}"`; tmux select-pane -R; tmux swap-pane -t $old'
bind-key -n "M-S-Left" run-shell 'old=`tmux display -p "#{pane_index}"`; tmux select-pane -L; tmux swap-pane -t $old'
bind-key -n "M-S-Down" run-shell 'old=`tmux display -p "#{pane_index}"`; tmux select-pane -D; tmux swap-pane -t $old'
bind-key -n "M-S-Up" run-shell 'old=`tmux display -p "#{pane_index}"`; tmux select-pane -U; tmux swap-pane -t $old'
bind-key -n "M-S-Right" run-shell 'old=`tmux display -p "#{pane_index}"`; tmux select-pane -R; tmux swap-pane -t $old'
bind-key -n M-x confirm-before "kill-pane"
bind-key -n M-/ copy-mode

# Linux system clipboard
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "xclip -in -selection clipboard"

# macOS system clipboard
#bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"
#bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "pbcopy"

set -g mouse on
set-option -g status-keys vi
set-option -g set-titles on
set-option -g set-titles-string 'tmux - #W'
set -g bell-action any
set-option -g visual-bell off
set-option -g set-clipboard off
setw -g mode-keys vi
setw -g monitor-activity on
set -g visual-activity on
set -g status-style fg=colour15
set -g status-justify centre
set -g status-left ''
set -g status-right ''
set -g status-interval 1
set -g message-style fg=colour0,bg=colour3
setw -g window-status-bell-style fg=colour1
setw -g window-status-current-style fg=yellow,bold
setw -g window-status-style fg=colour250
setw -g window-status-current-format ' #{?#{==:#W,#{b:SHELL}},#{b:pane_current_path},#W} '
setw -g window-status-format ' #{?#{==:#W,#{b:SHELL}},#{b:pane_current_path},#W} '
# For older tmux:
#setw -g window-status-format ' #W '
#setw -g window-status-current-format ' #W '

Now tmux feels like a regular desktop app and truly boosts the productivity in the terminal. What do you think?

Apr 25, 2020


以上所述就是小编给大家介绍的《Tmux for mere mortals》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

分布式机器学习:算法、理论与实践

分布式机器学习:算法、理论与实践

刘铁岩、陈薇、王太峰、高飞 / 机械工业出版社 / 2018-10-20 / 89.00

人工智能和大数据时代,解决最有挑战性问题的主流方案是分布式机器学习!本书旨在全面介绍分布式机器学习的现状,深入分析其中的核心技术问题,并且讨论该领域未来的发展方向。 由微软亚洲研究院机器学习核心团队潜心力作!鄂维南院士、周志华教授倾心撰写推荐序! 本书旨在全面介绍分布式机器学习的现状,深入分析其中的核心技术问题,并且讨论该领域未来的发展方向。 全书共12章。第1章是绪论,向大家展......一起来看看 《分布式机器学习:算法、理论与实践》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

SHA 加密
SHA 加密

SHA 加密工具