The One Eyed Fighting Kirby is basically a Vim substitution command that uses capture groups to transform text. The name comes from the way the regex capture group looks like a one-eyed Kirby (you know, the pink puffball from Nintendo games) when written in Vim. It’s a fun name for a powerful regex capture group technique that can save you tons of time when editing text.

Here’s the basic syntax:

:s/\(.*\);/console.log(\1)

How Does It Work?

Let’s break it down:

  • :s starts the substitute command
  • \(.*\) is our “One Eyed Fighting Kirby” - it captures everything between the parentheses
  • The \1 in the replacement part puts back whatever was captured

Real World Example

Let’s say you have some JavaScript code like this:

[1, 3, 4];
[3, 4];
[6, 7];

And you want to add console.log() to each line. Instead of doing it manually, you can use the One Eyed Fighting Kirby:

:%s/\(.*\);/console.log(\1);

This will transform your code into:

console.log([1, 3, 4]);
console.log([3, 4]);
console.log([6, 7]);

This can be used to add something to only a section of text.

const a = 1;
const b = 2;
const c = 3;
:%s/const \(.*\) = \(.*\);/const \1 = "\2"
const a = "1";
const b = "2";
const c = "3";