Vim + Tmux

How to make Vim your IDE for cross language development

By Nick LaMuro

Vim + Tmux

What to Expect

What to expect from this talk

What to expect from me

What I expect from you

What is Vim?

History of Vim…

…just kidding

The gist of it…

Vim Screenshot

Why Vim?

The Advantages of Vim

Demo

Basics

Movement

Vim movement

Modes

Vim modes (Modal Development)

That’s it!

Okay fine…

Technically there are more then three modes, but they are mostly subsets of the three previously mentioned. If you are curious and want to learn more, type :help vim-modes while in Vim to learn more.

In Vim, help docs are available inline on a variaty of subjects regarding Vim. Just use the :help [keyword] to get started.

Copy/Paste

Vim: Copy/Paste

Save and Quit

Vim: Save/Quit

Open a new file: :e path/to/file

Hardly worth it’s own slide…

Advanced functions

Buffers

Vim: Buffers

Vim: Buffers cont.

One thing to keep in mind is that by default, vim won’t let you switch between buffers without saving the current buffer you are in first. This gets old pretty quick, and is not helpful when you are just using one file as a reference.

To get around this, you can set the ‘hidden’ option (:set hidden) which will let you swtich between buffers freely and keep your undo history for each.

Splits

Vim: Splits

Vim: Splits cont.

Find and Replace

Vim: Find and Replace

Configuration

Vim Configuration

Enter the .vimrc

Vim: The .vimrc

.vimrc settings

Useful settings:

.vimrc keybindings

My .vimrc

https://gist.github.com/1147370

Plugins

Vim: Plugins

Vim: Noteable Plugins

What is Tmux?

What is Tmux?

So basically this:

Tmux Screenshot

Why Tmux?

and why not just use splits in iTerm2

Tmux: Why Tmux?

Demo

Installation

Installation

Install from source

Install Instructions:

$ wget http://downloads.sourceforge.net/project/tmux/tmux/tmux-1.6/tmux-1.6.tar.gz
$ tar -zxvf tmux-1.6.tar.gz
$ cd tmux-1.6
$ ./configure
$ make
$ sudo make install

Attach and Detach

Tmux: Attach and Detach

Windows and Panes

Tmux: Windows and Panes

Configuration

Tmux: Configuration

Tmux: Configuration Cont.

We are about to make a lot of changes to the .tmux.conf, and restarting tmux everytime is no picnic. To make this easier, we can reload tmux by running the following command:

source-file ~/.tmux.conf

This is similar to reloading your .bashrc when you make changes. To make this even easier, you can bind this to a key mapping:

bind-key r      source-file ~/.tmux.conf; display-message "~/.tmux.conf is reloaded"

Tmux: Configuration Cont.

Tmux: Configuration Cont.

Movement in tmux also doesn’t default to something that you are propbably already comfortable with: the Vim key bindings, so you can make some changes to make using tmux similar to Vim

Change movement keys:

bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

Change how you resize panes:

bind-key J resize-pane -D 5
bind-key K resize-pane -U 5
bind-key H resize-pane -L 5
bind-key L resize-pane -R 5

Change copy mode: set-window-option -g mode-keys vi

Tmux: Configuration Cont.

These are just a few more configs that are nice:

set -g base-index 1    # start window index of 1

set -sg escape-time 1  # fixes some delay issues in vim

bind-key a      send-key C-a   # `Ctrl-a a` sends `Ctrl-a`
bind-key n      command-prompt 'rename-window %%'
bind-key N      command-prompt 'rename-session %%'
bind-key -r <   swap-window -t :-
bind-key -r >   swap-window -t :+

# Copy mode keybindings
unbind p
bind p paste-buffer
bind -t vi-copy 'v' begin-selection
bind -t vi-copy 'y' copy-selection

My .tmux.conf

https://gist.github.com/1687643

Addons

Tmux: Addons

There really aren’t a lot of addons that you need for tmux…

Tmux: Brian Hogan’s Tmux Book

This book is not only a great intro to tmux, but was also a great reference for me when writing these slides.

tmux: Productive Mouse-Free Development

Tmux Book

It’s only $11, so you have no excuse not to get it!

… unless you don’t have $11…

Vim with Tmux

Nick LaMuro

Twitter @nicklamuro

github https://github.com/NickLaMuro

Slides http://talks.nicklamuro.com