If you enjoy the command line then you don’t need to be sold on efficiency or purity of action. But even those who grok CLI are unaware of a number of ways to be more elegant accomplishing their tasks. Here are a few of my favorites.
- Remap Your CAPSLOCK Key
ctrl-rFor History Autocomplete
- Switch to iTerm on OS X
- Switch to Zsh
- Remap your Vim Escape Key
- Remap your Vim Leader Key
- Use vi-mode in Your Shell
tmuxto Your Workflow
- Synchronize Your Environments
When was the last time you used your CAPSLOCK key? Yeah, me too. It’s a relic, and it’s right there on the home line wasting useful real estate. Let’s make it functional by remapping it to the Control key! Here‘s how to do it in various operating systems.
Now you can stay on your home keys and hit
ctrl-whatever with your pinky to the left the ‘a’ key.
Many know about using the arrow keys to invoke previous commands from history, but relatively few know that you can invoke
ctrl-r to be brought to a history auto-complete prompt.
Once you find what you were looking for you can hit enter and execute it or you can modify it before doing so. And now that your CAPSLOCK key is remapped, it’s easy to get in the habit.
iTerm isn’t necessarily an efficiency, but it’s definitely an improvement. Some features:
- Split panes
- Mouseless copy
- Paste history
- Full screen
- Expose tabs
- Tagged profiles
I’ve never known anyone to switch to iTerm and then switch back. Definitely give it a go.
Most come up using Bash as I did, and have to be shown the merits of another shell. After having multiple people rave about it I gave it a chance and haven’t gone back. Some features:
- Expand [remote] paths
ve/pl/re --> vendor/plugins/redmine
- Expand variables:
- Intelligent correction:
- Spelling correction
- Shared command history across running shells
- Highly themable prompts
- Most of your Bash configuration will work seamlessly
- Can emulate Bash when run as /bin/sh
- Supports vim mode commands
- OhMyZsh support
The last one is critical, as ohmyzsh makes using the shell an absolute pleasure by including a massive number of plugins (rails, git, OS X, brew, etc.), over 80 terminal themes, and an auto-updater. Definitely give it a try.
Having multiple modes in vim isn’t so much of an issue; it’s more that it sucks to move between them. The ESC key is a bit out of the way, and it doesn’t need to be. The first thing I do when I stand up a new vim environment is add some mappings to my
inoremap jj <ESC>
If you’re not familiar with the leader key and what it can do for you, you should start there. It basically serves as the activation key for shortcuts you can define. So you can say:
nnoremap j VipJ
This will make it so that pressing your leader key combined with the letter ‘j’ will visually select the entire paragraph and then join the lines in it.
I personally use the comma key ‘,’ as my leader since the concept is barely moving off of my home keys. So here I can activate all my shortcuts by using ‘,’, and leave insert mode by pressing ‘jj’. You can map it like so in your
let mapleader = “,”
Whether you’re using zsh or bash you want to be using the same muscle memory as much as possible, and if you’re a vim user that means switching your shell from Emacs mode (default) to vi mode.
This means you edit your shell commands the same way you edit inside vim:
bto go back a word
ddto delete the entire line
0, $to move to the line ends
You do this by adding the following line to your
You can also map your alternate escape key just as you do in vim (shown for zsh):
bindkey -M viins ‘jj’ vi-cmd-mode
Another added bonus here is that you navigate your history via
j,k as will come natural, and you can even have your
ctrl-r functionality as well by adding this to your
bindkey ‘^R’ history-incremental-search-backward
tmux is a terminal multiplexer, which allows you to connect to and manage multiple server-side terminal sessions. You can spin them up, connect to them, disconnect from them, and then connect to them another time or from somewhere else.
You may be familiar with a similar solution, GNU Screen, but
tmux has a number of advantages over screen:
- screen is a largely dead project, and its code has significant issues
- tmux is an active project with a modern, efficient codebase
- tmux is completely client/server based whereas screen tries to emulate this behavior
- tmux supports both vim and emacs key layouts
- tmux supports autorenaming windows based on what’s running
- tmux is easily scriptable from the shell
- vertical window splitting is native in tmux, as opposed to being bolted on and buggy in screen
If you’re not using terminal multiplexing, give tmux a try and enjoy the benefits. [ UPDATE: I now have a full primer on tmux here. ]
It’s quite annoying to have a brilliant shell and vim experience on your MBP, only to have it look and feel completely different when you SSH into your Linux boxes. Fix that by syncing up.
- Create a git repository for all your customization files, e.g., Bash, Zsh, Vim, etc. and keep it updated.
- Go to each of your systems that you use and clone that directory so that you’re working with one set of files across your environments.
- A commenter mentioned using Dropbox for synchronization as well, which seems attractive, but I’m not sure how clean that would be on headless Linux servers.
Ping me with similar tips so I can incorporate them into my workflow and add them here for others.