Brew Tmux



vim + tmux: A Perfect Match

Tmux is a terminal multiplexer, which means it will allow you to easily switch between several programs in one terminal, and it is especially handy when dealing with complex projects that require multiple terminals. Many developers have found Tmux an essential tool to boosting their productivity. ^ This is the nuclear approach. An alternative way would be to switch back to the old version if tmux with brew switch tmux then gracefully exit out of all of your sessions. Then switch back to the latest version and create new sessions. When you start tmux with the tmux command, you're automatically put into a new window. At the bottom of the status bar, you can see the window's ID, along with its name. The asterisk (.) indicates the current window you're in. Starting tmux for the first time, you're put into a window with ID 0.

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 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

Brew Tmux

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

Brew Tmux

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

Brew Install Tmux

You no longer have to be dependent on your terminal application to create split panes.

Ctrl-b %

Split vertically

Ctrl-b '

Pane Navigation

KeybindingAction
Ctrl-b ↑Up
Ctrl-b ↓Down
Ctrl-b ←Left
Ctrl-b →Right
</tr>

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.

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

Brew Tmux

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.

Tmuxjnnoremap knnoremap hnnoremap l```### rspec.vim + tslime.vimOne thing that I missed when I was transitioning from emacs to vim wasrspec-mode. I quickly discovered [rspec.vim](https://github.com/thoughtbot/vim-rspec) which allows you to run specs from within your editor.I didn't spend too much time working with rspec.vim before I wasfrustrated by the default behavior which blocks the entire vimprocess. This is no fault of rspec.vim, rather it is more of anissue with vim. Thankfully rspec.vim has a lot of flexibility forgenerating custom commands and you can easily integrate with[Dispatch](https://github.com/tpope/vim-dispatch) or[tslime.vim](https://github.com/jgdavey/tslime.vim). I am currentlyusing tslime.vim using the instructions[here](http://robots.thoughtbot.com/running-specs-from-vim-sent-to-tmux-via-tslime)and it seems to be working well.### vim-like copy and pasteI am still learning the ins and outs of copy and paste while using vim and tmuxtogether. If you're willing to give up using the mouse for selection [thisarticle](http://robots.thoughtbot.com/tmux-copy-paste-on-os-x-a-better-future)provides instructions on getting copy and paste setup very similar to vim.### colorsWhen I first started vim inside of tmux the colors were not correct. Aftersearching I found that I needed to add this to my tmux.conf:```set -g default-terminal 'screen-256color'```I also had to make sure that iTerm2 was reporting the terminal type as`xterm-256color`.## ReferencesThis article was made possible with the help of many other articles:[http://blog.sanctum.geek.nz/reloading-tmux-config/](http://blog.sanctum.geek.nz/reloading-tmux-config/) [https://wiki.archlinux.org/index.php/tmux](https://wiki.archlinux.org/index.php/tmux) [http://robots.thoughtbot.com/a-tmux-crash-course](http://robots.thoughtbot.com/a-tmux-crash-course) [https://coderwall.com/p/j9wnfw](https://coderwall.com/p/j9wnfw) [http://robots.thoughtbot.com/tmux-copy-paste-on-os-x-a-better-future](http://robots.thoughtbot.com/tmux-copy-paste-on-os-x-a-better-future) [http://www.dayid.org/os/notes/tm.html](http://www.dayid.org/os/notes/tm.html) [https://github.com/altercation/solarized/issues/159#issuecomment-5566892](https://github.com/altercation/solarized/issues/159#issuecomment-5566892) [http://stackoverflow.com/questions/10158508/lose-vim-colorscheme-in-tmux-mode](http://stackoverflow.com/questions/10158508/lose-vim-colorscheme-in-tmux-mode) [tmux manpage]:http://manpages.ubuntu.com/manpages/precise/en/man1/tmux.1.html
KeybindingAction
Ctrl-lright
Ctrl-kup
Ctrl-jdown
Ctrl-hleft
</thead></tr></table>This assumes you're already navigating your vim splits like a sane person usingthese bindings by adding this setting to your .vimrc:```nnoremap

Brew Tmux.conf

Related Posts

Brew Tmux-cssh

Install

Brew Tmux Config

Want to learn about the types of products we build?

Check out our projects