As modern developers, we can be tempted to jump into coding projects or tasks on a whim, using tutorials or guides found online as a starting point. With the power of Google at our fingertips, we can easily look up code snippets, tool features, commands, and concepts on the fly in order to utilize them in our workflows.
However, taking the time to learn and integrate a set of core ideas into our development workflows will help clear our minds while working and improve productivity.
It stands to reason that when searching for a productivity boost, targeting the tools that we use most frequently will often yield the greatest benefit.
As a developer, I find that a majority of my time is spent working on the Command Line or coding in my text editor. Therefore, in this article I will describe some basic productivity features of the user-friendly Fish shell and the Vim text editor. More specifically, I will discuss the autocompletion suggestions and spell checking features of these two tools.
Even if you haven’t used these tools before, it is well worth taking them for a test spin due to the productivity boost you can gain. The same goes for someone who has used the tools but is unaware of these features. Sharing tips and tricks like these with other developers is great for team building and will help you stand out from the crowd.
Background on Shells
Before jumping in, I wanted to introduce the idea of a shell. The shell determines the interface that will be available to us when entering commands at the Command Line. Shells provide useful functionality like tab autocompletion, directory traversal, and recording a history of executed commands. Some popular shells include:
- BASH (Bourne Again Shell): Probably the most popular shell in use today.
- ksh (Korn Shell): An older but still popular shell with similar functionality to BASH.
- Zsh (Z Shell): A high-performance shell gaining popularity. In 2019 it was chosen as the new default shell for Mac OS X.
- Fish (Fish Shell): A user-friendly shell with many features geared toward a great user experience. (My favorite!)
If you’d like to follow my lead and try out the Fish Shell, use the installation steps on their website.
Command Suggestions in Fish
Most traditional shells, like BASH, offer basic tab completion that allows the user to start typing a command or path and complete it by pressing the tab key. If multiple matches are found, pressing tab a second time will list all available options. This boosts productivity by saving keystrokes, which adds up quickly over time.
However, Fish doesn’t simply seek to replicate the style of traditional shells—its goal is to optimize the user experience. In addition to standard tab completion, Fish uses the command history as well as additional knowledge about specific commands to suggest likely completions for partially-typed commands.
These suggestions are displayed in gray (inactive) text to the right of the user’s active command and are updated dynamically while the user is typing. The user can scroll through different suggestions using the up and down arrow keys. Assuming the suggestion matches the user’s desired command or path, it can be applied (activated) using the right arrow key.
As I mentioned, Fish can actually provide context-relevant suggestions for specific commands. One popular example of this is its support for Git commands. Fish knows how to examine a Git repository to obtain information like branch names and files that have been staged for commit.
Fish uses this information to suggest command completions that are strikingly accurate—it feels as though Fish is reading your mind when it predicts which files you want to commit or which branch you want to merge!
When using tab autocompletion with multiple matches, Fish will not only display the matching command or path names. It will also try to provide additional information about each entry, such as a brief description and/or file size of each result.
Subsequent tab presses will expand the full list of results and toggle through them one by one. The user can start typing at any point in this process to display a search bar that can be used to filter down the results.
After using Fish for the first time, it became clear to me how much time its intuitive interface would save me. As a complement to this, let’s take a look at some similar productivity features of the Vim text editor.
Background on Vim
Vim is a popular open-source Command Line text editor that was released in 1991 by Bram Moolenaar. It is primarily used by developers to edit code files without having to leave the Command Line but is also well suited to general writing projects.
Vim’s interface allows users to switch between several modes that allow interacting with text in different ways. The default mode that is active when Vim is opened is called Command Mode, which is used to navigate around the text document and issue useful commands by typing a colon followed by the desired command. The second most common mode is Insert Mode, which allows users to directly type text into the document.
Vim has hundreds of commands and shortcuts that allow efficient editing of text from within the Command Line. Vim emphasizes a workflow that minimizes the number of keystrokes needed to perform sequences of actions and offers multiple solutions for minimizing repetitive tasks. Vim ships with a built-in tutorial called
vimtutor, which can significantly speed up the learning curve for beginners.
For more general information about Vim, check out the Vim website.
Spell Checker and Autocompletion in Vim
Vim ships with a built-in English word list that can be used as a dictionary for spell checking within text files. In order to enable spell checking, open a file in Vim’s Command Mode and type:
:set command can be followed by various options, (in this case
spell), to enable or disable different functionality in Vim.
After this command is run, misspelled words in the text document will be highlighted with special formatting, usually underlined with a dashed red line or something similar, depending on the format theme in use.
In Command Mode, the
]s command can be used to jump to the next misspelled word. Similarly, the
[s command can be used to jump to the previous misspelled word. The
z= command will pull up a list of suggested corrections for the misspelled word under the cursor.
Each suggested correction in the list is associated with a number. The user can choose which correction to apply by entering the number associated with that correction and pressing <ENTER>. If no correction is desired, pressing <ENTER> will simply exit the suggested correction list without changing anything.
Vim also provides a handy way to efficiently correct mistakes that were typed earlier in the active line. While in Insert Mode, the command
<CTRL-x><CTRL-s> can be used to jump to the last mistake and automatically display a drop-down list of suggested corrections.
Vim’s built-in dictionary can also be used to provide autocompletion suggestions while typing. For this to work, Vim’s spell checker must be enabled using the
:set spell option as we saw previously. Simply start typing a word in Insert Mode and then type
<CTRL-x><CTRL-k>. This will display a drop-down menu containing a list of autocompletion suggestions from Vim’s dictionary.
Items in the list can be scrolled using the up and down arrow keys or by using
<CTRL-p> to move to the previous entry and
<CTRL-n> to move to the next entry. By using the similar command
<CTRL-x><CTRL-k><CTRL-p>, Vim will allow you to continue typing (or deleting) characters in your word while it filters down the autocompletion suggestion list in real time.
Small Time Savings Add Up
In this article, we covered some productivity features of the Command Line tools Fish and Vim. We discussed how Fish shell’s Command suggestions can save time by reducing the number of keystrokes required when working on the Command Line.
We also detailed how to enable Vim’s spell checker for suggesting corrections and autocompletions while we work.
If you’re a new developer looking to get your feet wet with the Command Line and programming in general, check out the book Coding Essentials Guidebook for Developers by Initial Commit.
If you’re looking for a book specifically for tips and tricks using Vim, check out the book Practical Vim.
Putting in the effort to master these tools is well worth it since small time savings add up in the long run. Although learning something new can seem intimidating at first, with a little bit of practice over a stretch of a few weeks, you can pick up a new skill that will reap rewards for the rest of your career.