Show HN: I built a little browser game to practice Vim commands (hjkl.duy.run)
I made hjkl to help myself remember Vim commands. It’s a little browser game you can play when you want to unwind and get a bit of Vim practice in.
There are still a lot of commands I want to add, but I hope someone finds it useful in the meantime :)
54 comments
[ 0.15 ms ] story [ 27.9 ms ] threadOne note: It might be useful to keep the "undo" prompt when the user messes up after the first two prompted lessons for a clear recovery path.
Thank you for making this!
Where dw works, this game teaches vlllld instead, which is a bad habit to teach.
Ctrl+A increments the first number after the cursor, which is easier than, say, f6r7 in cases where they do the same thing. Similarly, Ctrl+X decrements.
t:t: is weird when fY is much easier.
The Vim simulator has a minor difference compared to real Vim:
0 0
Start on line one and do CTRL-V then j then CTRL-A. Real Vim would increment both. The simulator only increments the one under the cursor.
also there is an opportunity to turn this into something like vim.golf but in the browser
It does not make sense to me that I should use an editor I need to study and practice for. It can't possibly that much more efficient, especially given that usually speed is not the limiting factor for what I do.
Maybe one day I will be tempted to find out why it's supposedly worth it again.
https://helix-editor.com/
It is. And I’m not even an advanced Vim user.
> especially given that usually speed is not the limiting factor for what I do.
For me it’s not so much about speed as about comfort. Jumping into VISUAL and selecting something in a block, yanking the line, jumping pages, editors, searching within the file, filtering, sorting. And the most important part is that because it is so old and widespread there’s pretty much vim mode for any editor so I can use the same shortcuts between vim, VScode, IntelliJ, etc.
do the thing you enjoy :)
The funniest time I did this was with a interview screening question which had a hundred-deep chain of links with the URL for the next link embedded in some JSON with some additional formatting required to get a working link. Vim let me copy a line of text that's a curl command, shell out to replace it with the ~6 lines of JSON response, edit that as a string down to a curl command to the next URL, and wrap that entire process up as a macro to run a hundred times.
I learned Vim because I didn't like using Nano to edit server configs, and ended up sticking with it because I wanted to ditch my mouse in my workflow for fear of long-term RSI development.
Vimtutor is a built-in command in Vim and Neovim, and I personally wish I started with it since it's super helpful. You only have to learn as much as you need to, to become productive and then you can progressively get more advanced with macros and piping the file contents to a command line tool like jq.
Edit: Lastly, vi(m) keybinds exist in a surprising number of GNU/Linux utilities and it's worhwhile to learn those at least, e.g. git's built-in pager uses a subset of vi(m) keybinds and so does `less`.
[1]: https://web.archive.org/web/20180318023156/https://www.viemu...
I stopped after learning enough to get by but can see how having all of it learned and automatic would be pretty efficient.
Macros are really neat as well. Basically, think through the motions to do a particular edit, even if it's very convoluted, maybe 20 motions, then you can record it and play it back, repeat it any number of times (like to do the same edit to 100 lines in a row), or save it to a keybind in your config. Macros can also include commands and [vim] window management. Like I have two files I work in side by side a lot and I made a bind to delete the second line of both files and save both files. Under the hood it is very manually jumping to line 2, deleting, saving the file, swapping windows, doing the same, swapping back at the end. When played back it appears as though it did just what you wanted instantly, though. If I ever find I'm doing a bunch of repetitive manual steps like that a lot, I think about whether a macro saved to a keybind would be a good idea.
I use vim for personal notes, editing configs, managing playlist (.m3u) files, etc. I'm not a programmer.
Other commenter mention stuff like yanking, moving lines, selecting blocks, word-level and line-level operations, scrolling pages, that's all stuff that editors can absolutely do (despite what vim-lovers say) and sometimes do it better as they're semantics-aware ("go to function arguments" is possibly in intellij but not really in vim, and vim block selection doesn't work in indented languages like YAML or Python). Recording macros? Intellij has it.
Editors don't do stuff like "delete the next 5 lines" or "delete up to line 38", but I find that I never do that in Vim: if I have to count lines or look up the line number, might as well do a selection as I go and then just press "delete", or to delete a small chunk of lines and press "." (repeat) until I'm done. More keystrokes, but no cognitive effort so faster overall.
Sure, there's stuff like executing some command you have selected and piping the result into your vim buffer, mixing that in with macros... Vim is probably the fastest way to do this sort of stuff, but I have use for that maybe once every three months? It'd take me more time to look up how to do it with vim than to do it manually.
If you really get serious with it, you can probably be much faster with Vim than I am. If that's something you're interested in, go for it, but IMO that's closer to a hobby than anything else. Editing speed rarely is the bottleneck as you say. Still kinda nice to have consistent keybindings across editors, and I find vim pretty good for freetext notes.
There's a bit of a hump you have to jump through when you're first getting used to having separate modes for input and editing / navigation, but that's honestly the worst part.
After that, you just need to notice things that you need to do often, and then go "I bet vim makes that easy." You pick up a little trick and use it. You probably don't remember it the next time, but you remember there was a way, and you look it up again and reinforce it. You eventually remember the things that were useful to you, and forget the "tricky stuff" that wasn't.
Over time, you start getting your head around how it works, the whole verb / subject thing, and then you start learning to speak the language. You stop thinking "ok, i need to go to normal mode, then type c, then in, then t" and start thinking "change inside tag".
Vim's not really about "editing super fast." It's more like a different mental model of editing text that really, genuinely, is better than the default mode on offer in your standard text editor. It's more keyboard driven and composable and just _capable_. Text editing operations that are annoying in standard editors are trivial in vim.
I think these little games are neat, but ultimately wrongheaded. The best way to learn vim is to use vim to do vim things. I've been using vim (or, more often, vim editing modes in VSCode or IDE du jour) for around a decade, and I bet I don't use 95% of what it can do. But that 5% I do know is extremely useful.
Also though: it's a nerdy text editor, and it's fine if you don't like it or want to learn to use it.
/s