How to Transform a (part of) Buffer in Vim with an External Program

The aim of this page📝 is to explain transformation of buffer/its part within Vim by running it via another Unix program.

Pavol Kutaj
Sep 11, 2024

Example#1: Deduplication

  • Use :%!sort | uniq to sort and remove duplicates.
  • % represents the entire file in Vim.
  • :%! runs an external command on the entire file.
  • Useful for applying changes globally without specifying line numbers.
  • sort sorts the lines alphabetically.
  • uniq removes consecutive duplicate lines.

Example#2: Base64 encode decode

  • Visually select a string to encode (Shift-V for line is enough)
  • press : to enter command-line
  • enter ‘<,’>!base64 → the range is encoded !
  • the range is replaced with base64 representation of the selection

--

--

Pavol Kutaj
Pavol Kutaj

Written by Pavol Kutaj

Today I Learnt | Infrastructure Support Engineer at snowplow.io with a passion for cloud infrastructure/terraform/python/docs. More at https://pavol.kutaj.com

No responses yet