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:
| |
How Does It Work?
Let’s break it down:
:sstarts the substitute command\(.*\)is our “One Eyed Fighting Kirby” - it captures everything between the parentheses- The
\1in the replacement part puts back whatever was captured
Real World Example
Let’s say you have some JavaScript code like this:
| |
And you want to add console.log() to each line. Instead of doing it manually, you can use the One Eyed Fighting Kirby:
| |
This will transform your code into:
| |
This can be used to add something to only a section of text.
| |
| |
| |