Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active December 5, 2018 17:23
Show Gist options
  • Save nepsilon/1abe9a699f4aee93a897b438542d3355 to your computer and use it in GitHub Desktop.
Save nepsilon/1abe9a699f4aee93a897b438542d3355 to your computer and use it in GitHub Desktop.
3 Vim tips with external commands — First published in fullweb.io issue #95

3 Vim tips with external commands

Vim has this ! special character that will run any shell command without having to close it. Here are 3 ways I often use it:

1. Format a JSON blob:

:%!python -m json.tool

2. Count number of characters in a file:

:! wc -c %

3. Load a directory listing:

:r ! ls -1 /my/dir

The possibilities are virtually unlimited. Remember % will be replaced with the current filename, and :r (:read) will copy the output of what follows into the current file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment