Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active July 6, 2021 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirrajan/a075445a93e2121aee162b2c84329581 to your computer and use it in GitHub Desktop.
Save amirrajan/a075445a93e2121aee162b2c84329581 to your computer and use it in GitHub Desktop.
My tmux config: ~/.tmux.conf
# ~/.tmux.conf
# * brew install tmux reattach-to-user-namespace
# * C-a - Your leader <l> key.
# * <l>: - Type command not handled by shortcut keys. Eg: <l>: kill-pane ENT
# * <l>r - Reload this file/config.
# * <l>j - Select split using number jump list.
# * <l>{ - Swap splits left.
# * <l>} - Swap splits right.
# * <l>| - Create vertical split.
# * <l>- - Create orizontal split.
# * C-hjkl - Move around between splits.
# * C-HJKL - Resize splits.
# * <l>z - Toggle "fullscreen" for split.
# * <l>c - New frame.
# * <l>n - Cycle frame.
# * <l>SPC - Cycle layouts.
# * <l>a - Enter Copy Mode/Scrolling Mode.
# The following commands are only available in copy mode.
# ** y - Yank selection/exit copy mode.
# ** hjkl - Navigate/move cursor
# ** C-b - Page up.
# ** C-f - Page down.
# ** C-u - Half page up.
# ** C-d - Half page down.
# ** v - Character copy mode.
# ** V - Line copy mode.
# ** C-v - Block copy mode.
# ** <l>= - View kill ring.
# ** ? - Search for text up.
# ** / - Search for text down.
# The following command are available after enter a search term.
# *** n - Next result.
# *** N - Previous result.
set -g mouse on
set -g prefix C-s
set -g display-time 4000
set -g display-panes-time 4000
bind s send-prefix
unbind C-e
unbind C-s
unbind C-b
unbind C-m
unbind C-a
unbind C-j
unbind C-l
unbind C-h
bind j display-panes
bind m setw synchronize-panes
bind C-a last-window
set -s escape-time 1
set -g base-index 1
setw -g pane-base-index 1
bind r source-file ~/.tmux.conf \; display "Reloaded!"
bind C-s send-prefix
bind | split-window -h
bind - split-window -v
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim(diff)?$|emacs.*$' && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim(diff)?$|emacs.*$' && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim(diff)?$|emacs.*$' && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim(diff)?$|emacs.*$' && tmux send-keys C-l) || tmux select-pane -R"
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
set -g default-terminal "screen-256color"
set-option -g default-command "reattach-to-user-namespace -l $SHELL"
setw -g mode-keys vi
unbind [
bind Escape copy-mode
unbind p
bind p paste-buffer
bind-key -T copy-mode Tab
unbind -T copy-mode-vi Space
unbind-key -T copy-mode-vi Enter ; bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
set -s -g escape-time 0
unbind-key -T copy-mode-vi C-v ; bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
set-option -g history-limit 50000
;; https://github.com/keith/evil-tmux-navigator
;;; navigate.el --- Seamlessly navigate between Emacs and tmux
;; Author: Keith Smiley <keithbsmiley@gmail.com>
;; Created: April 25 2014
;; Version: 0.1.5
;; Keywords: tmux, evil, vi, vim
;;; Commentary:
;; This package is inspired by vim-tmux-navigator.
;; It allows you to navigate splits in evil mode
;; Along with tmux splits with the same commands
;; Include with:
;;
;; (require 'navigate)
;;
;;; Code:
(require 'evil)
(defgroup navigate nil
"seamlessly navigate between Emacs and tmux"
:prefix "navigate-"
:group 'evil)
; Without unsetting C-h this is useless
(global-unset-key (kbd "C-h"))
; This requires windmove commands
(when (fboundp 'windmove-default-keybindings)
(windmove-default-keybindings))
(defun tmux-navigate (direction)
(let
((cmd (concat "windmove-" direction)))
(condition-case nil
(funcall (read cmd))
(error
(tmux-command direction)))))
(defun tmux-command (direction)
(shell-command-to-string
(concat "tmux select-pane -"
(tmux-direction direction))))
(defun tmux-direction (direction)
(upcase
(substring direction 0 1)))
(define-key evil-normal-state-map
(kbd "C-h")
(lambda ()
(interactive)
(tmux-navigate "left")))
(define-key evil-normal-state-map
(kbd "C-j")
(lambda ()
(interactive)
(tmux-navigate "down")))
(define-key evil-normal-state-map
(kbd "C-k")
(lambda ()
(interactive)
(tmux-navigate "up")))
(define-key evil-normal-state-map
(kbd "C-l")
(lambda ()
(interactive)
(tmux-navigate "right")))
(provide 'navigate)
;;; navigate.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment