💾 Archived View for sotiris.papatheodorou.xyz › gemlog › 20220425_viewing_tsv_files_in_vim.gmi captured on 2024-08-31 at 11:35:05. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-04-28)

-=-=-=-=-=-=-

Viewing TSV files in Vim

Tab-separated-values (TSV) are the simpler alternative to comma-separated-values (CSV). There's no need to quote anything which means you don't need a specialized library to generate or parse TSV, standard Unix tools are enough. I use them extensively for logs which are afterwards further processed using AWK. However there is one big annoyance when viewing those logs: the TSV columns aren't aligned, making it difficult to distinguish which column data belongs to. This is an issue with CSV files too but in the case of TSV it's fairly easy to solve in Vim.

Newer versions of Vim have an option called vartabstop. This allows specifying the tab width for each column separately. A small AWK script is enough to compute the appropriate value of vartabstop given some TSV data on standard input. I wrapped this in a Vim plugin imaginatively named vim-tsv and TSV files are now automatically shown with aligned columns. I also implemented another useful feature I read about on a blog post by Alan Grow, always showing the header line so you can see the column names when you scroll down.

Sotiris 2022/04/25

TSV file format specification

vim-tsv

Alan Grow's blog post