vim + tmux: A Perfect Match
tmux is a terminal multiplexer: it enables a number of terminalsto be created, accessed, and controlled from a single screen. tmuxmay be detached from a screen and continue running in thebackground, then later reattached.
Tmux is a terminal multiplexer. It allows you to have multiple terminal sessions opened up in a single terminal view. A terminal window split into three parts. Yes, there are modern terminal apps such as iTerm2 for Mac that can do the exact same thing. Sudo yum install tmux Install Tmux on macOS# brew install tmux Starting Your First Tmux Session# For your first session simply start tmux with a new session: tmux. This will create a new tmux session and start a shell in that window. This window shows a green status bar with information about current session. You can now run your first tmux.
– [tmux manpage][]
When I first heard of tmux I just assumed it was a beefed up version of screen.I had used screen many years ago in order to keep an IRC client logged in evenif I was not connected to my shell. At the time I didn’t see much benefit inadding a tool like this to my development environment.
For a long time I heard developers singing the praise of vim and tmux. Hearingabout the release of iTerm2 2.0 and it’s integration with tmux sparked myinterest in tmux and vim once again. I still don’t know exactly how iTerm2 andtmux integrate, but I’m really happy with my workflow with vim and tmux.
I have been using vim+tmux together for a couple of weeks now and there’s nolooking back. If you’re willing to invest a little bit of time to set thingsup, you’ll quickly make up the time with your streamlined workflow.
Prerequisites
brew install tmux
brew install macvim --override-system-vim
Download and install iTerm2 (optional)
Out of the Box
Below are some of the most basic commands for interacting with tmux.
Create a session
The first thing you’ll want to do after installing tmux is create a session.
$ tmux new -s gaslight-blog
Detach session
You can detach from the session at any point by pressing:
Ctrl-b d
Attach session
You can attach to the session from the command line with:
$ tmux attach -t gaslight-blog
Split horizontally
You no longer have to be dependent on your terminal application to create split panes.
Ctrl-b %
Split vertically
Ctrl-b '
Pane Navigation
Keybinding | Action |
Ctrl-b ↑ | Up |
Ctrl-b ↓ | Down |
Ctrl-b ← | Left |
Ctrl-b → | Right |
tmux.conf
I ran into numerous issues when starting out with vim, tmux, iterm2, and macos. My tmux.conf is prettyslim and well documented at the moment and I recommend you check it out.
Brew Tmuxp
vim workflow
The main reason that I continue to use tmux is the great integration that canbe achieved with vim+tmux. Prior to using tmux I used MacVim, but if you’regoing to use vim and tmux together you’ll need to use terminal vim.
vim-tmux-navigator
Perhaps my favorite feature about using vim and tmux together isvim-tmux-navigator. Thisplugin allows you to treat vim and tmux as one a unified session, with theability to seamlessly navigate between vim splits and tmux panes.
Keybinding | Action |
Ctrl-l | right |
Ctrl-k | up |
Ctrl-j | down |
Ctrl-h | left |
Related Posts
Want to learn about the types of products we build?
Check out our projectsMany people (including me) don’t want to use Homebrew. But if you search online for “How to install tmux on macOS” you will found mostly Homebrew descriptions. So here now the very easy solution without.
Requirements
- Command Line Tools installed
In case that Command Line Tools are not installed, execute following command and follow the installation steps in new popup window. This process can take some time, so be patient.
Installation
Brew Tmuxinator
To execute next steps you need to download and unzip two release tarballs. Here you will found latest version of libevent and tmux (ncurses is already installed on macOS).
Brew Tmux-cssh
That’s it already. If you’re new to tmux you should have a look on this Cheat Sheet.