The Decider said over 2 years ago permalink Comment? (1)
Tagged: tmux vim iterm iterm2

iTerm2, tmux and vim

Switching up my development environment.

Recently I came across some posts describing tmux, a gnu/screen alternative. I use screen quite a bit but only when doing remote system admin and really enjoy it’s features. Especially being able to attach to a session that was terminated due to connectivity problems.

I had never given a second thought about using screen on my dev machine since is so quick to jump between apps. However, after reading through the Giant Robots Post I have had a re-think. In some ways I feel as though I’m stepping back 20 years but has dev really changed at all in 20 years? Maybe some of our methodologies but not the general trend of Test-Code-Deploy-Repeat.

Anyway, there are 3 tools needed to make this work on my Mac.

  1. iTerm2
  2. tmux
  3. and the best editor in the world, vim

iTerm2

Probably any terminal will do but iTerm2 is much faster at resizing than iTerm and is actively being developed.

tmux

This is a terminial multiplexor with many of the features of gnu/screen but in my opinion easier to configure. Recommended Tutorial The port version is a bit dated so I recommend installing from source. Follow the instructions. It’s your basic configure, make, make install.

vim

Now normally I run MacVim on my mac. It’s pretty. The console version courtesy of Apple seems just fine. It reads my .vimrc with no issues and behaves just great with Tim Pope’s Rails plugin.

Modifying my Behavior

This is the hardest part of the switch. I really hate my mouse and really thought that I had shun using it for many years now. However, I find myself reaching for it to switch windows when a command-tab is easier. It’s strange if I’m in my terminal I always command-tab to chrome but for some reason reach for the mouse when switching to macvim. Now that macvim is no longer in the equation I still find myself reaching for the mouse to move from my bash tmux pane to my vim pane.

Speaking of panes I run tmux full screen divided into 3 panes.

tmux_vim_bash

my .tmux.conf file:

set -g prefix C-a
unbind C-b
bind C-a send-prefix

bind-key C-a last-window

# Set status bar
set -g status-bg blue
set -g status-fg white

# Highlight active window
set-window-option -g window-status-current-bg red

# Automatically set window title
setw -g automatic-rename

# use "v" and "s" to do vertical/horizontal splits, like vim
bind s split-window -v
bind v split-window -h

# use the vim motion keys to move between panes
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# use vim motion keys while in copy mode
setw -g mode-keys vi
# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf
#
# # quick pane cyclingunbind ^A
bind ^A select-pane -t :.+