vim.mdx58 lines · 2.0 KB · raw
1---
2title: Vim Shortcuts
3layout: ../../layouts/MainLayout.astro
4---
5
6# Vim Shortcuts in the REPL
7
8When the REPL editor (CodeMirror) is configured to use Vim keybindings, the following commands are available:
9
10- :w — Evaluate the current code
11
12  - Triggers the same evaluation as Ctrl+Enter / Alt+Enter
13  - You'll see messages in the Console panel such as:
14    - [vim] :w — evaluating code
15    - [repl] evaluate via event
16    - [eval] code updated
17
18- :q — Stop/pause playback
19
20  - Triggers the same stop action as Alt+.
21  - Useful to quickly stop scheduling without leaving Vim mode
22
23- gc — Toggle line comments for the current selection(s)
24
25  - Works in normal and visual mode
26  - If there's a selection, all selected lines are toggled
27
28Notes
29
30- Behavior respects the current language mode in the editor for comment syntax.
31- If multiple REPL editors are open, commands target the active editor. The implementation dispatches custom events handled by the editor.
32- If you don't see the Console panel, open the right panel in the REPL UI.
33
34Troubleshooting
35
36- If :w logs but evaluation doesn't apply, ensure Vim keybindings are active and try again. You can also use Ctrl+Enter as a fallback.
37- For :q / gc, ensure focus is inside the editor. If an error occurs, reload the page to reset editor state and try again.
38
39## Adding custom keybindings
40
41To add custom keybindings the `Vim` object can be used (either from within a pattern or in a prebake script)
42
43Example:
44
45```javascript
46// Map 'jk' to Escape in normal mode
47Vim.map('jk', '<Esc>', 'insert');
48// Map 'U' to :w (Evaluate the current code)
49Vim.map('U', ':w<CR>', 'normal');
50// Map 'Q' to :q — Stop/pause playback
51Vim.map('Q', ':q<CR>', 'normal');
52// Map 'J' to find next '$' (jump to next label)
53Vim.map('J', '/\\$<CR>', 'normal');
54// Map 'K' to find previous '$' (jump to previous label)
55Vim.map('K', '?\\$<CR>', 'normal');
56```
57
58For more information on how to use the `Vim` object see [CodeMirror Vim](https://github.com/replit/codemirror-vim)