A key binding only saves time once you press it without thinking. The way to get there is practice on real tasks, with a goal and a clock. :IdeTrainer is a small game inside Neovim that does exactly that for the keys of this series. It lives in the configuration from Part 15 and is written in plain Lua, with no extra plugins.

Why a game and not a cheat sheet

A cheat sheet tells you that gd jumps to a definition. A round puts the cursor on findCatalog in the controller, asks you to reach the declaration, and checks the result. You repeat it until the time drops.

The idea comes from vim-be-good, a well-known Neovim game for Vim motions. Existing trainers cover Vim motions, not the LSP, debugger and database keys a Java IDE adds, so this one was written for the series. For your very first steps in Vim, the built-in :Tutor is still the best start.

Start it

The plugin loads only when you run its command. Its spec in lua/plugins/ide-trainer.lua points lazy.nvim at a local folder:

{
  dir = vim.fn.stdpath("config") .. "/local-plugins/ide-trainer",
  name = "ide-trainer",
  main = "ide_trainer",
  cmd = "IdeTrainer",
}

:IdeTrainer opens a menu with five entries: Vim basics, IDE keys, long IDE rounds, both packs together, and your best times. :IdeTrainer stop quits at any time, and :IdeTrainer <round-id> plays a single round.

How a round works

A round opens in its own tab. A small window in the top-right corner shows the goal, a timer and your score. The first Vim round looks like this:

Round 1/14  ·  Move with h j k l
Put the cursor on the highlighted word
(the start of the constructor).
Hint in 6s
Time 2.9s   Score 0   :IdeTrainer stop

The target word is highlighted in the buffer. If you are still searching after eight seconds, the hint line shows which keys to use. The game checks the editor after every cursor move, text change and mode change, so the round ends the moment you reach the goal. In our test, 3j4l finished the round and a notification showed “✓ Move with h j k l”.

Scoring is simple. Each round has a par time. At or under par you get 100 points; slower runs get fewer, but never less than 10. Best times are saved in Neovim’s data folder, and the menu shows them.

The Vim rounds

The fourteen Vim rounds use a scratch buffer that holds the text of CatalogController.java, so you practise on real Java without touching a file:

  • moving with hjkl, w and b, 0 and $, f and t, / search, gg and G
  • editing with dw, ci", ci(, ciw, yy and p, and visual line mode
  • undoing with u, and splitting and switching windows with Ctrl-w

CatalogController.java

A wrong move does not end a round. Only the goal does.

The IDE rounds

IDE keys need a real project, a language server and a debugger. Start Neovim at the root of the companion code and choose “IDE keys”. The thirteen short rounds cover keys from earlier parts: gd and gr, finding a file, jumping to a diagnostic with ]d, a quick fix and organize imports, renaming across files, extracting a variable and a method, plain and conditional breakpoints, the dadbod sidebar, and an overseer task.

For the quick-fix round, the game breaks findCatalog( into findCatalogs( in the controller, without saving. You put the cursor on it, press <leader>ca and choose “Change to ‘findCatalog(..)’”. The round ends when the error is gone.

These rounds change real buffers, so the game protects your work. It refuses to start while you have unsaved buffers, it never writes a file, and it reloads every changed buffer from disk after each round. In our test, git status was empty after all thirteen rounds.

The long pack starts JVMs and takes minutes: run the nearest test, stop at a breakpoint, evaluate an expression in the debug REPL, and attach to a running JVM. The attach round is skipped unless something listens on port 5005.

How it was tested

Every round was played in a headless Neovim against the companion code, the Vim rounds with real keys and the IDE rounds through the same calls their keys make. All 14 Vim rounds, 13 IDE rounds and 4 long rounds passed. The menu, the corner window, the hint and the results screen were also checked by typing into Neovim inside .

The tests found four bugs, which were fixed before this part was written. One example: other modules of the companion code reuse the same file names, so the rounds now look only inside module-09-catalog.

Recap

  • :IdeTrainer opens a menu of timed practice rounds; :IdeTrainer stop quits.
  • Vim rounds run on a scratch buffer with the controller’s text; IDE rounds run in the real companion project.
  • A round ends only when the goal is reached; a hint appears after a few seconds, and best times are saved.
  • IDE rounds never write files and discard their edits after each round.
  • The plugin is plain Lua in local-plugins/ide-trainer and loads only on its command.

Series: Neovim as a Java IDE. Previous: A ready-made Neovim config for Spring Boot · Next: Flame graphs from Java Flight Recorder recordings

Sources

Official documentation and well-known tutorials read while writing this article. The wording here is our own.