Introduction to The Generative Review
A long time ago I created a little vim plugin in a day, and called it CtrlR. Now I’ll ask chatGPT to say a few words about the VimScript code.
This blog and newsletter is meant to explore the capability and idiosyncrasies of current AI, featuring code reviews raw, unedited (except when corrections are explicitly noted.)
You can receive the next installments, coming twice a month, the next issues will also come with interviews with ChatGPT that try to stretch the robot’s gritty brain-logic, as well as feature open source AI projects that need help, by pre-detailing a simple task/GitHub issue that can get you started, in the manner of a classifieds section (I once published a Clojure Open Source newsletter around this latter concept, in 2014.)
CtrlR.vim: what is it?
Included below, and redacted, is the README I wrote, about ten years since. Please note that CtrlR.vim has keybindings that go beyond the bash reverse-i-search functionality, when it is convenient to have them for vim use cases. The project is hosted on GitHub.
CtrlR faithfully emulates the reverse search functionality found in the Bourne-again shell. But how could I bind it to ctrl-R when it already does register insertion? By default, if you press ^R with an empty command line, the reverse-i-search will be brought up, whereas if you have typed anything, the native/vanilla action will be executed. This should be mostly intuitive since bash's own reverse search ignores anything you have typed so far when you invoke it (just earlier today while using ^R in bash I got why that is a brilliant feature, but now I can't seem to remember.)
ChatGPT, review this code
Disclaimer: this is an unedited output from ChatGPT, generated today. I have not editorialized the text, except for formatting some parts in bold, so that emphasis is mine, all the rest is AI.
This is a Vim plugin that provides reverse incremental search functionality, allowing you to quickly search and retrieve a previously entered command from the command line history.
It maps the Ctrl-R
key combination to the s:ctrlr()
function, which is defined at the end of the script. This function processes the user's key inputs to determine what to search for and what to return as the result.
When the Ctrl-R
key combination is pressed and the command line is not empty, the function looks up the value of the pressed key in a dictionary of key codes. Depending on the value, it may return the contents of a register (if the key pressed is a letter or symbol), the current word under the cursor (Ctrl-W
), the current WORD under the cursor (Ctrl-A
), the current line (Ctrl-L
), or a command string ending in the next unescaped backtick (Ctrl-M
).
If the command line is empty, the function enters a loop that repeatedly retrieves key inputs from the user and updates the search term and result based on these inputs. The Ctrl-R
key moves to the next match in the command history, Backspace
deletes a character from the end of the search term, Ctrl-U
clears the search term, and Ctrl-W
sets the search term to an empty string. The loop ends when the Escape
key is pressed. The search term is echoed to the command line and the selected match is returned as the result of the function.