Vim 的 UserGettingBored 自动命令
Vim's UserGettingBored Autocmd

原始链接: https://evanhahn.com/usergettingbored-vim/

Vim 的文档中包含一个幽默且无实际功能的事件,名为 `UserGettingBored`。尽管该事件出现在 Vim、Neovim 和 Vim Classic 的文档中,但它不会触发任何实际代码,如果使用还会导致报错。 该事件由 Vim 创建者 Bram Moolenaar 于 2000 年添加,最初描述称其会在用户按下“CTRL-C”时触发,随后附带了这是个玩笑的声明。2013 年,该描述被更新为当前版本:“当用户按下同一个键 42 次时。开个玩笑!:-)” 虽然该事件在核心软件中只是一个占位符,但它最终在 2022 年启发了一个非官方插件。这个插件终于让这个玩笑成为了现实:当用户在插入模式下按下同一个键 42 次时,它会显示一张塞缪尔·杰克逊(Samuel L. Jackson)的照片。

Hacker News 最新 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Vim 的用户感到无聊自动命令 (evanhahn.com) 9 分,作者:zdw,1 小时前 | 隐藏 | 过往 | 收藏 | 1 条评论 hmokiguess 7 分钟前 [–] 在某些方面,这让我想起了一些能检测驾驶员何时需要休息的汽车。真希望这能成为现实,有时候工作起来很容易忘我。 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 加入 YC | 联系 搜索:
相关文章

原文
Vim's UserGettingBored autocmd

In short: Vim has a joke autocmd called UserGettingBored that doesn’t do anything.

Vim’s automatic commands feature, usually shortened to “autocmd”, lets you run code when various events occur. For example, you could implement an auto-save feature by binding the TextChanged event to the :w command.

Vim has over 100 events, from “buffer was created” to “file was saved”. But one of them sticks out to me: UserGettingBored. Here’s the documentation:

UserGettingBored: When the user presses the same key 42 times. Just kidding! :-)

When I saw this, I was busy doing something else and it completely derailed me. “I must know more,” I thought.

Here’s what I found:

  • Unfortunately, it doesn’t do anything. It only exists in the documentation (and some tests). If you try to use it with somethig like autocmd UserGettingBored ..., you’ll get a “no such group or event” error.

  • It’s present in Vim, Neovim, and Vim Classic.

  • It was first added by Bram Moolenaar in July 2000, over a year before Vim 6.0 was released. The original description was, “When the user hits CTRL-C. Just kidding!” And it didn’t do anything back then, so I don’t think it’s ever been real.

  • In August 2001, he added the smiley face to the documentation. It then read, “When the user hits CTRL-C. Just kidding! :-)”

  • Twelve years later, in 2013, the description changed to its current iteration: “When the user presses the same key 42 times. Just kidding! :-)”

In 2022, developer Mike Smith created an unofficial plugin inspired by this joke autocmd. If you press the same key 42 times in Insert mode, a picture of Samuel L. Jackson appears. 22 years later, it’s finally real.

联系我们 contact @ memedata.com