Skip to content

Instantly share code, notes, and snippets.

@sebmaynard
Last active December 29, 2015 15:19
Show Gist options
  • Save sebmaynard/7689568 to your computer and use it in GitHub Desktop.
Save sebmaynard/7689568 to your computer and use it in GitHub Desktop.
Enable ctrl-<arrow> keys for moving between tmux and emacs panes (requires emacs, tmux and zsh). This allows you to use ctrl-<arrow> to switch panes in an emacs split, and then move to the nearest tmux pane once you get to the edge of the emacs window. Particularly useful if you have tmux split with emacs in one pane, and zsh in another
set-window-option -g xterm-keys on
sebpane-down() { tmux select-pane -D }
sebpane-up() { tmux select-pane -U }
sebpane-left() { tmux select-pane -L }
sebpane-right() { tmux select-pane -R }
zle -N sebpane-down
zle -N sebpane-up
zle -N sebpane-left
zle -N sebpane-right
bindkey '^[[1;5B' sebpane-down
bindkey '^[[1;5A' sebpane-up
bindkey '^[[1;5D' sebpane-left
bindkey '^[[1;5C' sebpane-right
((lambda ()
(require 'windmove)
(defun sebwindmove (thewindmovefun thetmuxparam)
"wrap windmove commands, and if there's no window above, try switching tmux pane instead"
(interactive)
(condition-case nil
(funcall thewindmovefun)
(error (shell-command (concat "tmux select-pane " thetmuxparam)))))
(defun sebwindmove-up () (interactive) (sebwindmove 'windmove-up "-U"))
(defun sebwindmove-down () (interactive) (sebwindmove 'windmove-down "-D"))
(defun sebwindmove-left () (interactive) (sebwindmove 'windmove-left "-L"))
(defun sebwindmove-right () (interactive) (sebwindmove 'windmove-right "-R"))
(global-set-key (kbd "C-<left>") 'sebwindmove-left)
(global-set-key (kbd "C-<right>") 'sebwindmove-right)
(global-set-key (kbd "C-<up>") 'sebwindmove-up)
(global-set-key (kbd "C-<down>") 'sebwindmove-down)
;; xterm bindings for the same
(global-set-key (kbd "M-[ 1 ; 5 c") 'sebwindmove-right)
(global-set-key (kbd "M-[ 1 ; 5 d") 'sebwindmove-left)
(global-set-key (kbd "M-[ 1 ; 5 a") 'sebwindmove-up)
(global-set-key (kbd "M-[ 1 ; 5 b") 'sebwindmove-down)
;; xterm in tmux bindings for the same (!)
(global-set-key (kbd "M-[ c") 'sebwindmove-right)
(global-set-key (kbd "M-[ d") 'sebwindmove-left)
(global-set-key (kbd "M-[ a") 'sebwindmove-up)
(global-set-key (kbd "M-[ b") 'sebwindmove-down)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment