If you’re a programmer like myself who has taken college courses or picked up the trade through books and online resources, you may have come across a terminal-based text editor called vim. And you may have heard of tmux, which is a terminal program that produces virtualized consoles in useful formats.

This article is for the beginner. For the beginner who’s been using Sublime or Notepad++ and wants to make the first step to change.

 

Why you should try the combination of the two?

Tmux provides the virtual consoles to split and provide windows for movement around terminal UNIX systems. Vim has many keyboard shortcuts that speed development. Assuming that you have both Tmux and Vim, here are some commands to get started.

 

Tmux

To initiate Tmux on your machine, you must type in tmux. By default, machines will not have Tmux. You will need to install it.

tmux

Screen Shot 2015-07-14 at 10.57.40 PM

After you have initiated Tmux, all commands and shortcuts with Tmux are triggered by pressing Ctrl-b and another command.

Ctrl-b
Tmux Windows

Windows are very useful. Think of windows as alternative tabs that can be switched through Tmux shortcuts. Press Ctrl-b and quickly press another one of these commands.

I use windows all the time. Create windows if you want easy tabs that can be switched through shortcuts. I enter Tmux, create one window to edit files and another window to run the file. Because I use git, I like to have a third window for pushing files onto Github.

Type in exit to delete windows.

I use vim for editing the first window.

Screen Shot 2015-07-14 at 11.54.55 PM

I typically use a second window for running the file or going into other directories and editing files.

Screen Shot 2015-07-14 at 11.56.13 PM

Lastly, I use one window for using git.

Screen Shot 2015-07-14 at 11.57.17 PM

Tmux Panes

Panes can be thought as sections of the terminal window. You can set up vertical and horizontal splits with panes. Panes on Tmux are used more for having one bird’s eye view of the directory structure in one pane while editing files in the other pane.

Screen Shot 2015-07-15 at 12.46.54 AM

You can use Ctrl-b with the directionals to switch between panes.

I don’t usually use the Tmux panes when working with Vim. I normally only use Tmux windows, and in each of those windows, I tend to split with Vim panes instead. Vim panes allow you to copy and paste easily to other Vim panes.

 

Vim

Vim is a powerful customizable terminal text editor. It’s especially great for editing text on remote machines. Let’s go over the basic commands to edit in Vim.

vim filename

Vim Panes

When I use Vim, I use other shortcuts for traversing through the files that we won’t get in this article. We’re talking about workflow. I use :vsplit filename to open another one of my files on a separate screen.

:vsplit filename.txt

Screen Shot 2015-07-15 at 2.45.14 AM

Screen Shot 2015-07-15 at 2.45.41 AM

Alternatively, Vim uses Ctrl-w as it’s shortcut trigger key for splitting windows.

Copying and pasting with Vim

To copy and paste within vim, you need to enter Visual mode or Visual Line mode.

Visual modes are used for manipulating the file in a number of ways such as copying and pasting. Once in Visual mode, you can copy, paste, and delete across panes, which comes to be really useful for editing multiple files.

The difference between Visual Line mode and Visual mode is that line mode manipulates lines while visual mode manipulates characters one at a time. I can copy across Vim panes:

Screen Shot 2015-07-15 at 3.07.35 AM

 

Working with both

Vim has many more shortcuts for moving around the text editor, but as for my workflow with Vim, I normally use Tmux for windows, switching between instances of vim running. I use Tmux normally to hold other windows where I can move around directories or use other programs like git. Try the two together and see what fits right for you.