Skip to content

Instantly share code, notes, and snippets.

@drwebb
Created August 2, 2015 03:57
Show Gist options
  • Save drwebb/c3123f598a373e0bc838 to your computer and use it in GitHub Desktop.
Save drwebb/c3123f598a373e0bc838 to your computer and use it in GitHub Desktop.
Emacs and tmux window move integration
# Tmux bit
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"
;; Emacs bit
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
;;; navigate.el --- Seamlessly navigate between Emacs and tmux
;; Author: Keith Smiley <[email protected]>
;; 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""')'))')')')
## Tmux bit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment