I have devised an entirely new method of sorting numbers. Quicker1 than quicksort, more EFFERVESCENT than bubblesort, I present to you:
Vim Macro Sort Vim Macro Sort uses NO Vimscript, NO chicanery with control characters, and it NEVER leaves normal mode. It’s just a plain old ASCII text file with a bunch of editing commands in it.
Try It Out! Start using this new sort macro TODAY!
Download macrosort.txt, open with the command: vim --clean macrosort.
When I found out that Bram had died I posted a short thread on Mastodon, but I haven’t written anything here yet because I haven’t quite been able to work out why it hit me as hard as it did and what I wanted to say about it.
Two months on, I still haven’t really figured it out, so I’ll just say that, by all accounts, Bram was an exceptionally generous person, and note that in the handful of extremely limited interactions I had with him I always came away feeling positive, which hasn’t always been my experience with other open source projects.
Vim’s insert mode completion has a very nice feature where you can start typing a natural language word and then press Ctrl-XCtrl-K to complete it.
By default, it pulls the words used for the completions from the file specified with your 'dictionary' option, but this requires you to have such a file, which is not always1 the case for the computers I do my Vimmin’ on.
But there is a backup!
Tim Chase posted a clever little :substitute command on Twitter:
Had some regex with lots of repeated \d in them like \d\d\d\d
Converted them all to \d{n} notation in vim using
:%s!\%(\\d\)\{2,}!\='\d{'.(strlen(submatch(0))/2).'}'!g
Just in case it's useful for anybody else.
— Tim Chase (@gumnos) May 18, 2023 As always, my instinct was immediately to see if you can do it as a macro1.
You can. Here’s how:
qqqqq/\v(\\d)+\zs\\dEnterc2l{2}Esc@qq@qqq/\\d{\d}{2}EnterCtrl-All3x@qq@q
(Yes, this is actually two recordings.
Because vimclippy is a shell command, iVim users may fear they are OUT OF LUCK when it comes to FAST clipboard-editing, and that they are doomed to forever tapping out "*P…:%y* like NEANDERTHALS.
But there is a way.
Step 1: Create a User-Defined Command First we’re going to set up a :VimClippy Ex command to insert the current content of the clipboard into a buffer and set up the autocommand to write the edited text back into the clipboard when the buffer is saved.
Waaay back in 2018, Julia Evans wrote this terrific post about how to edit a BUNCH of files by writing a little ed script. You should absolutely go read the whole post where she explains how to use ed to perform a sequence of edits she’d normally do in Vim.
I just want to add the note that the code she ends up with is also perfectly valid Vimscript. So you can run the EXACT same script in Vim!
When I first started my plan to concoct a classically recursive macro, I got as far as writing a complete, functioning implementation before I stopped to think and realised that what I’d been working on wasn’t actually a recursive algorithm at all but was in fact iterative. 🤦
But even though the macro below doesn’t actually fulfil the brief, I’m still kind of proud of the method I came up with for incrementing and testing the loop index, so I thought I’d post it here for posterity.
Insert mode’s CTRL-A was one of those Vim features that I knew about for ages but didn’t get the point of until someone showed me this ONE WEIRD TRICK1 that uses it to ASTONISHING effect2. I added it to my toolkit, and after a while found myself using CTRL-A in loads of other scenarios too!
The :help for CTRL-A in insert mode is… shall we say… concise:
CTRL-A Insert previously inserted text.