Neovim: Manipulate Markdown Tables with Awk

Gareth Stretton
9 min readApr 20, 2024

This article shares how to manipulate markdown tables inside of Neovim using the ‘Awk’ command. The operations include: create table, add column, delete columns, extract a column's values, swap columns, clear row, format table, and sort table. The columns can be specified by name or column number.

A previous article shared how to do with using bash scripts. But Awk is a more natural and better choice. So I re-wrote those scripts in Awk.

My goals were to:

  • avoid programming “into the editor” itself (for example, using Neovim’s Lua, or Obsidian’s JavaScript API)
  • rely on out-of-the-box system commands to “do the work”
  • create something “universal” by not choosing a specific programming language, that is, use capabilities that come with the operating system

Awk ticks most of these boxes. While it is scripting language, it does come with Linux/Mac and is designed specifically to process lines of a file or text streams. You can create some powerful ‘transformations’ with just a few lines of code. And when called from your text editor, offers an easy way to create new functionality.

The rest of this article shares each feature, including the code and a short animation demonstrating it’s usage. When quirky syntax crops up there are a few notes to explain.

Each script should be made executable with chmod u+x SCRIPT_NAME and placed on your system path, e.g. update…

--

--

Gareth Stretton

Entrepreneur, software engineer, electronics enthusiast, creator, dad, husband, inventor. What brings me joy is creating and sharing. https://ko-fi.com/gahrae