A command-line terminal can be great for productivity. But while sticking with defaults may keep you portable, customized settings (along with practice of advanced features) are really the keys to improved comfort and efficiency. These are a few that I find especially useful.

Environment variables

Many pieces of software actually respect some useful shell environment variables. The most significant one on modern systems is EDITOR, which should of course be reset to /usr/bin/vim. On older systems, you may also want to set PAGER to /usr/bin/less, as the classic more pager just doesn’t live up to modern expectations.

Vim behavior

Vim’s default settings vary considerably by Linux distribution and release, and many are very much personal preference. My own rather minimal config on Ubuntu 16.04 sets incsearch, hlsearch, and showcmd, which, when combined with that OS’s defaults, yields an environment similar to the Gentoo one I learned on.

But one objective improvement that has eluded me until recently is a fix for the long pause sometimes encountered after typing shift + O to insert a new line above the current one in command mode. It turns out that, when typed shortly after Esc (to enter command mode), this is indistinguishable from entering an escape sequence. Vim uses a timeout to try to separate such sequences from manual input, but, presumably for robustness over low-bandwidth links, the default timeout is quite long. The solution is to reduce it with the following line in your ~/.bashrc:

" We're not manually typing escape sequences, so don't stall after, e.g. Esc O
set ttimeoutlen=10

Using a short but non-zero value should prevent issues should a real escape sequence be split into different packets in a network protocol (this risk may be hypothetical, but I experienced no issues over a cross-country SSH link).

One Vim setting I am still searching for is to allow pasting without auto-indentation when autoindent is enabled (and without having to explicitly enter and exit paste mode). Many suggested solutions for middle-click pastes rely on Vim being mouse-aware, but I prefer to operate it in a pure terminal mode. I remember RHEL 5 having my preferred behavior by default, but I don’t know what combination of configs and compile options achieved it.

Commands and aliases

Among the most common command-line activities are searching for files based on filename and contents. Such tools are of course provided out-of-the-box (find, grep), but invoking them with commonly useful settings can be needlessly verbose. My recommended solutions are the following:

For searching for filenames, I use an alias (technically, a bash function) to do a case-insensitive search from the current directory for the argument anywhere in the filename. I can imagine improvements, such as searching for multiple unordered substrings (a feature in many IDEs) or ignoring files not managed by the governing RCS, but fnd meets my needs in 90% of cases and is much faster to type than its expansion.

fnd() {
    find . -iname \*$1\*
}

When it comes to searching by contents, as good as grep is, I prefer ripgrep (rg). It is recursive by default, knows which files to ignore when within an RCS, and is very fast on a wide variety of file types and search strings. It’s not quite as snappy as git grep with a Git repo (it doesn’t just use the repository index to enumerate files), but it’s fantastic in so many other ways (its benchmark page is really worth a read). If you’re set up for Rust development, installation is as easy as:

cargo install ripgrep