Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 16, 2022 03:12 pm GMT

Making tmux suck less

tmux is a great tool. But it's basically unusable out of the box. Try it - fire it up in a bare environment without a tmux config file. You'll have no colors. You'll have weird keybindings issues. The vim clipboard will be broken. Copying text with your mouse will be broken (unless you really did want to copy random bits of text from all of your panes, and not just the active one). In short, you'll have a terrible user experience.

I foolishly thought tmux would inherit all of the niceties of my base terminal emulator. As it turns out, tmux behaves a lot more like a standalone terminal than an add-on to your existing one. I can respect a tool that assumes nothing about its use, but it does mean you have to do some configuring to make it work well for you. Here's what I did:

1. Enabling colors

Add this to your .tmux.conf

set -g default-terminal "xterm-256color"

2. Fixing weird keybind issues

For me, adding this to my config solved it:

set-window-option -g xterm-keys 

It's been a while, so I'm not totally sure what problem it was that it solved, but I think it was this

3. Highlighting and copying text with the mouse

Credit to this SO post

Add this to your .tmux.conf:

set -g mouse onbind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"bind -n WheelDownPane select-pane -t= \; send-keys -Mbind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -Mbind -T copy-mode-vi    C-WheelUpPane   send-keys -X halfpage-upbind -T copy-mode-vi    C-WheelDownPane send-keys -X halfpage-downbind -T copy-mode-emacs C-WheelUpPane   send-keys -X halfpage-upbind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down

and install xclip

sudo apt install xclip

Turning mouse mode on will also enable you to scroll each pane with the mouse wheel, and select panes with the mouse.

4. Set prefix to `

I prefer the prefix to be a single key. I thought using ` as the prefix and enabling entering it when pressing the key twice quickly was an elegant solution.

unbind C-bset -g prefix `bind-key ` send-prefix

5. Add a theme

While not strictly necessary, adding a theme to tmux really does make it look way cooler. On a functional note, though, some themes update what information is shown in the bottom status bar by default, which can really improve the user experience.

I went with a simple powerline theme from the tmux-themepack.

Putting it all together

Here's my .tmux.conf:

set-window-option -g xterm-keys onset -g default-terminal "xterm-256color"unbind C-bset -g prefix `bind-key ` send-prefixsource-file "${HOME}/repos/tmux-themepack/powerline/default/purple.tmuxtheme"set -g mouse onbind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"bind -n WheelDownPane select-pane -t= \; send-keys -Mbind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -Mbind -T copy-mode-vi    C-WheelUpPane   send-keys -X halfpage-upbind -T copy-mode-vi    C-WheelDownPane send-keys -X halfpage-downbind -T copy-mode-emacs C-WheelUpPane   send-keys -X halfpage-upbind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down# To copy, left click and drag to highlight text in yellow, # once you release left click yellow text will disappear and will automatically be available in clibboard# # Use vim keybindings in copy modesetw -g mode-keys vi# Update default binding of `Enter` to also use copy-pipeunbind -T copy-mode-vi Enterbind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection c"bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"

Original Link: https://dev.to/dizzyspi/making-tmux-suck-less-97e

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To