1. Home
  2. Changelog

Jul 20, 2021

Piping Vim text directly through Unix commands

Gary Bernhardt

10 min → 0:59

Overview

Gary Bernhardt demonstrates his terminal-centric development workflow, showing how he manages instances of the text editor Vim and integrates them deeply with Unix shell commands.

3 things to know

Terminal-Based Vim

The practice of using Vim entirely within a command-line terminal, forgoing a graphical user interface (GUI) for speed and integration.

▶ Watch at 1:48

Shell Command Integration

Piping selected text from Vim directly to any external shell command (like `sort` or `git blame`) and having the output replace the selection, blending the editor and the shell.

Unix Philosophy & Job Control

Leveraging core Unix features like job control (`Ctrl+Z` to suspend, `fg` to bring to foreground) to manage Vim sessions without needing multiple terminal windows or panes.

Also in this episode

Language-Agnostic Autocomplete

Utilizing Vim's built-in keyword completion, which works across any text file (code, prose, etc.) by tokenizing words from all open files, independent of language-specific tooling.

Quotes

“It means that the better you get at the shell, the better you are at using Vim... and the better you get at Vim also will let you use your shell commands more.”

▶ Watch at 2:05

“Vim is deeply integrated with Unix in a a way that graphical editors aren't.”

▶ Watch at 1:48

“I run Vim in the terminal all the time. I don't even have a graphical Vim installed.”

▶ Watch at 0:33

Full summary

Episode Overview

  • This clip is a preview of a special episode of The Changelog podcast focused on the text editor Vim.
  • It features a demonstration by guest Gary Bernhart, creator of Destroy All Software and Execute Program.
  • Gary showcases his workflow, which involves running Vim exclusively within the terminal and integrating it deeply with Unix shell commands.
  • The demonstration highlights how to manage Vim instances, execute shell commands, and leverage Vim's built-in features for a powerful, terminal-centric development environment.

Key Concepts

  • Terminal-Based Vim: The practice of using Vim entirely within a command-line terminal, forgoing a graphical user interface (GUI) for speed and integration.
  • Unix Philosophy & Job Control: Leveraging core Unix features like job control (Ctrl+Z to suspend, fg to bring to foreground) to manage Vim sessions without needing multiple terminal windows or panes.
  • Shell Command Integration: Piping selected text from Vim directly to any external shell command (like sort or git blame) and having the output replace the selection, blending the editor and the shell.
  • Language-Agnostic Autocomplete: Utilizing Vim's built-in keyword completion, which works across any text file (code, prose, etc.) by tokenizing words from all open files, independent of language-specific tooling.

Quotes

  • At 00:33 - "I run Vim in the terminal all the time. I don't even have a graphical Vim installed." - Gary Bernhart explaining the foundation of his editor workflow.
  • At 01:48 - "Vim is deeply integrated with Unix in a a way that graphical editors aren't." - Highlighting the core advantage of his terminal-based approach.
  • At 02:05 - "It means that the better you get at the shell, the better you are at using Vim... and the better you get at Vim also will let you use your shell commands more." - Describing the synergistic relationship between mastering the shell and mastering Vim.

Takeaways

  • Run Vim in the terminal to create a fast and seamless workflow between your editor and shell commands.
  • Master Unix job control (Ctrl+Z, fg) to manage editing sessions within a single terminal, improving efficiency.
  • Leverage Vim's ability to filter text through shell commands (!sort, etc.) to perform powerful transformations without leaving the editor.
  • Explore Vim's built-in, buffer-based autocomplete, which is effective for any text type, not just code.

Watch the full episode 10 min

Read along with the audio summary

Gary Bernhart does not even have a graphical version of the text editor Vim installed on his computer. In this preview of a special episode of The Changelog podcast, which came out on July 20, 2021, the creator of Destroy All Software and Execute Program demonstrates his development workflow. By the end, you will learn how to run Vim exclusively in the terminal to integrate it deeply with Unix shell commands.

Gain speed and integration by ditching your graphical user interface, or GUI. Gary says he runs Vim in the command line terminal all the time. He explains that this approach makes Vim deeply integrated with Unix in a way that graphical editors are not.

Working in the terminal also lets you manage your editing sessions without opening multiple windows or panes. Instead of juggling screens, you can rely on core Unix job control features. Pressing Control and Z suspends your session, and typing the letters f and g brings it right back to the foreground.

Blend your editor and your shell to transform text on the fly. You can pipe selected text from Vim directly to any external shell command, such as sort or git blame. The output from that command immediately replaces your original selection.

Get keyword completion that works across both code and prose without needing language specific tools. Vim includes a built in autocomplete feature that works on any kind of text file. It does this by breaking words into tokens across all of your open files, or buffers.

Running Vim in the terminal creates a powerful environment where your editor and shell work together. "It means that the better you get at the shell, the better you are at using Vim, and the better you get at Vim also will let you use your shell commands more."

More from Changelog

Related Episodes