Most of the time, when I'm not using Vim, I'm probably hanging around in the command line. Thankfully, there is no lack of excellent CLI tools. Here I'd like to share some of them and how I use them.
For a TL;DR, scroll to the bottom where you'll find a short list with the links.
tldr
Man pages is a fantastic place to look for a documentation and learn how a program works but sometimes what we need is to quickly have a look at examples of how a particular tool should be used. For example I never remember how should to send a POST request with curl
.
tldr does just that — prints a short description and then gives you the possible ways of usage. With the most common example at hand I can quickly copy what I need and run.
- For Alfred users, here is the workflow for it.
- And yes, there's a Vim plugin but somehow I don't find it too useful.
rupa/z
I can't imagine living without this little script. It tracks my most frequently used directories along with the frequency, and then it lets me jump to a directory by typing a partial path.
For example, when I want to get to ~/projects/web/vimfromscratch
, I just type z vimf
and then hit Enter
.
I would also suggest changing the default command name from z
to j
(as this is much easier for your fingers). You can either create an alias, or set the global env variable:
export _Z_CMD="j"
I have to mention, there are some alternatives you can try:
diff-so-fancy
This tool is a drop-in replacement for diff
or git diff
. It does the same thing but does it with style. The default colors are much nicer, and the diff shows changes within the same line (see the screenshot).
In order to make it your default Git pager, run this:
git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
Then also, you can replace your default diff
by setting an alias:
alias diff="diff-so-fancy"
Bat
Now that we started talking about syntax highlighting, have you ever thought of how cat
is a bit boring? Wouldn't it be nice if it was able to highlight the syntax of a file that it's printing out?
The answer to this question is bat. bat
adds a syntax highlighting for a large number of languages. Plus, it is integrated with Git, so it will show what has changed in the file you're viewing.
You would want to replace your older model:
alias cat="bat"
You can colorize you man page by exporting:
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
For other interesting integration, please have a look at the README.
ripgrep
Ripgrep is an alternative to ag
(the silver searcher). It is significantly faster, and also it comes with some sane default behaviour, like respecting your .gitignore
file.
As you can see on the screenshot, the output is clear, and the search pattern is highlighted in the output results which is nice.
exa
Another drop in replacement you can use instead of the build-in ls
command is Exa. Again, as some other tools in this article exa
provides color highlighting and some sane defaults but overall remains compatible with ls
API.
alias ls="exa"
# I usually use this command instead
alias l="exa -lahF"
fd
By this time, you probably already figured out that if there is a replacement for some built-in command, I would probably have it installed.
Meet fd, a faster alternative to find
. The problem with find
is that as I can never remember how to use it. Should it be find myfile.py
, or find --name myfile.py
, or is it with a single dash? Should I add .
before or after the search pattern? Argggh.
With fd
, it's always straightforward fd myfile.py
. Again that's about saner defaults and beautiful colorized output (see the screenshot).
Don't forget to
alias find="fd"
Fzf
Oh yes, I saved the coolest for the end. Fzf (fuzzy finder) is a super fast tool written in Go which does just one thing: It takes a list of lines as an input and then let's a user fuzzy search in them for some text.
While that may not sound too impressive, the fun part begins with the applications.
For example, try
vim $(fzf)
You'll be prompted with a list of files, and you can search among those. After you press enter
, the selected file will open in Vim.
Or, you try pressing Ctrl+R
(the command that runs the command history in the shell). You can now fuzzy search among your commands, then press enter
to execute it.
While searching for a file, Fzf
can give you a nice preview (see the screenshot), you just need to specify the preview command:
fzf --preview="bat {} --color=always"
Remember the rupa/z
script? Fzf
integrates with it nicely, so if you run z
without arguments you can fuzzy search among your most frequently used directories.
Honestly, the list of possibilities how you can use it is really endless. Sky is the limit. Try browsing this page with examples.
What is this thing you're using?
In case you want to know, here is what my setup is based on:
- iTerm2 terminal
- Menlo typeface
- Afterglow colorscheme
- Z shell with oh-my-zsh configuration framework
-
Custom theme for
oh-my-zsh
- The numbers you see on the screenshots are
ruby
andnode
versions.
Tl;DR
- tldr for quickly viewing the usage examples
- rupa/z for jumping between directories
- diff-so-fancy for better diffing
-
bat to replace
cat
with - ripgrep for searching pattern within text files
-
exa a colorful and fast
ls
-
fd a drop-in replacement for
find
- Fzf for fuzzy search
P.S.: I'm writing a book on Vim for developers. Feel free to check it out.
Top comments (4)
Hi Yanis,
Thanks for sharing your list. Particularly I'd never seen diff-so-fancy, I like how it enhances readability on the CLI and its integration with git. I'm also a big fan of tldr pages because it's helped me spend less time fighting with the terminal.
There's a CLI tool I'm working on that I think you're gonna like :). It lets you explain commands right from your terminal. Please check it out at github.com/ediardo/kmdr-cli, I'd like to hear what you think about it.
Hi!
It looks very nice, great job!
To tack onto this, you may appreciate
git-shelf
, which enables some better logic around storing "work in progress" with git, as an alternative to bothgit-stash
making commits on the tree you're working on.github.com/sudoforge/git-shelf
Where is jq? :)