Exposing Vim from codemirror-vim
Docs for adding keybindings Only expose Vim from keybindings
This commit is contained in:
parent
0a2f2eaa3d
commit
a9752fb2a4
3 changed files with 24 additions and 0 deletions
|
|
@ -4,3 +4,4 @@ export * from './flash.mjs';
|
||||||
export * from './slider.mjs';
|
export * from './slider.mjs';
|
||||||
export * from './themes.mjs';
|
export * from './themes.mjs';
|
||||||
export * from './widget.mjs';
|
export * from './widget.mjs';
|
||||||
|
export { Vim } from './keybindings.mjs';
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,8 @@ const keymaps = {
|
||||||
vscode: vscodeExtension,
|
vscode: vscodeExtension,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export { Vim } from '@replit/codemirror-vim';
|
||||||
|
|
||||||
export function keybindings(name) {
|
export function keybindings(name) {
|
||||||
const active = keymaps[name];
|
const active = keymaps[name];
|
||||||
const extensions = active ? [Prec.high(active())] : [];
|
const extensions = active ? [Prec.high(active())] : [];
|
||||||
|
|
|
||||||
|
|
@ -35,3 +35,24 @@ Troubleshooting
|
||||||
|
|
||||||
- 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.
|
- 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.
|
||||||
- For :q / gc, ensure focus is inside the editor. If an error occurs, reload the page to reset editor state and try again.
|
- For :q / gc, ensure focus is inside the editor. If an error occurs, reload the page to reset editor state and try again.
|
||||||
|
|
||||||
|
## Adding custom keybindings
|
||||||
|
|
||||||
|
To add custom keybindings the `Vim` object can be used (either from within a pattern or in a prebake script)
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Map 'jk' to Escape in normal mode
|
||||||
|
Vim.map('jk', '<Esc>', 'insert');
|
||||||
|
// Map 'U' to :w (Evaluate the current code)
|
||||||
|
Vim.map('U', ':w<CR>', 'normal');
|
||||||
|
// Map 'Q' to :q — Stop/pause playback
|
||||||
|
Vim.map('Q', ':q<CR>', 'normal');
|
||||||
|
// Map 'J' to find next '$' (jump to next label)
|
||||||
|
Vim.map('J', '/\\$<CR>', 'normal');
|
||||||
|
// Map 'K' to find previous '$' (jump to previous label)
|
||||||
|
Vim.map('K', '?\\$<CR>', 'normal');
|
||||||
|
```
|
||||||
|
|
||||||
|
For more information on how to use the `Vim` object see [CodeMirror Vim](https://github.com/replit/codemirror-vim)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue