Tmux configuration: Difference between revisions

From wikinotes
No edit summary
Line 23: Line 23:
= Syntax =
= Syntax =
<blockquote>
<blockquote>
== Conditionals ==
<blockquote>
Tmux supports conditionals in configuration.<br>
For example here I bind clipboard operations if we're running an [[xorg|xorg server]].
<syntaxhighlight lang="bash">
if-shell -b 'test -n ${DISPLAY}' {
    # selection automatically copied to selection-clipboard
    bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe "xclip -i"
    # yank copies to selection-clipboard
    bind y run-shell -b "tmux show-buffer | xclip -selection c -f > /dev/null && tmux show-buffer | xclip -i > /dev/null"
}
</syntaxhighlight>
</blockquote><!-- Conditionals -->
== Format Variables/String Interpolation ==
== Format Variables/String Interpolation ==
<blockquote>
<blockquote>

Revision as of 17:12, 18 September 2021

This page documents some commands I use most frequently.

Documentation

keybindings https://man.archlinux.org/man/community/tmux/tmux.1.en#KEY_BINDINGS
mouse https://man.archlinux.org/man/community/tmux/tmux.1.en#MOUSE_SUPPORT

Locations

~/.tmux.conf config

Syntax

Conditionals

Tmux supports conditionals in configuration.
For example here I bind clipboard operations if we're running an xorg server.

if-shell -b 'test -n ${DISPLAY}' {
    # selection automatically copied to selection-clipboard
    bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe "xclip -i"

    # yank copies to selection-clipboard
    bind y run-shell -b "tmux show-buffer | xclip -selection c -f > /dev/null && tmux show-buffer | xclip -i > /dev/null"
}

Format Variables/String Interpolation

Format variables may control command output, or can be referred to within commands.
These format variables can be nested.
See format variables for details.

# sample use in command output

# sample use in keybinding
bind-key 'Y' new-window -c '#{pane_current_path}'

Commands

notifications

set -g display-time 5000                     # message display duration
display-message -c /dev/pts/0 'hello world'  # show a message

terminal

set -g default-terminal "screen-256color"  # desired $TERM value
set -g visual-bell off
set -g visual-activity off
set -g bell-action current

mouse

set -g mouse on

statusbar

set -g pane-base-index 1
set -g status-position top
setw -g clock-mode-style 2

source-file

source-file ${FILE}  # import file

keybindings

See KEYBINDINGS section in man page.

Keys are bound within tables. by default, they are bound to the prefix table (active following tmux-prefix keyseq).
Keys executed without a prefix are defined in the root table.
bind and bind-key can be used interchangeably.

tmux bind-key \
  [-n] `# bind w/o prefix (root table)` \
  [-r] `# repeatable` \
  [-N ${NOTE}] \
  [-T ${KEY_TABLE}] \
  ${KEY} \
  ${TMUX_COMMAND} ${ARGUMENTS[@]}
bind-key     F1   set-option status off   # bind key-sequence
bind-key -n  M-0  select-window -t 10    # bind key-sequence to root table (no prefix reqd)

unbind C-b                               # unbind key-sequence

tmux prefix

set -g prefix 'M-a'                      # set (additional) alternative tmux-prefix

enable vi mode

set -g mode-keys vi
set -g status-keys vi