To fg or not to fg...

There's limitless variation for a Vim and shell-based workflow. I like to stay in Vim most of the time, switching to other windows for command-line tools with tmux. In my office I've noticed a seasoned Vim veteran using Vim and then backgrounding it to run shell commands. He'll switch back when he needs Vim.

This style has its advantages -- you could use shells inside Vim, but that's perhaps only useful if you want to get results into Vim easily. Also, pressing CTRL-Z to suspend Vim requires less key presses than the CTRL-A n or CTRL-A hjkl I press for navigating between tmux windows and panels.

Typing fg in most shells will bring a backgrounded process to the foreground. If you're running Vim and press CTRL-Z, you're actually causing the SIGSTOP signal to be sent to the process. The fg command is built into your shell, so each shell has its own quirks.

In Zsh, fg supports autocomplete. You can have multiple suspended versions of Vim and switch between them using fg [tab], which displays a menu for each instance:

$ fg %vim
%1  -- vim
%2  -- vim test.js

I don't usually do this because I like to use a single instance of Vim with windows and tabs, but you might like it if you want to use an instance of Vim per project.

blog comments powered by Disqus