• Stars
    star
    214
  • Rank 184,678 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

VIM keybindings for monaco editor

monaco-vim

Vim keybindings for monaco-editor demo

npm version

Install

Webpack/browserify

npm install monaco-vim
As global

This package will only work when bundled using webpack/browserify or using AMD. Including globally is not possible due to the use of an internal dependency of monaco-editor which is not exposed in the API. Loading 'monaco' globally is also not possible as you'll have to use its loader.js file. If you are using that, then there will be no problem. See AMD.

Usage

import { initVimMode } from 'monaco-vim';

const vimMode = initVimMode(editor, document.getElementById('my-statusbar'))

Here, editor is initialized instance of monaco editor and the 2nd argument should be the node where you would like to place/show the VIM status info.

To remove the attached VIM bindings, call

vimMode.dispose();

Handling key presses

If you would like a particular keypress to not be handled by this extension, add your onKeyDown handler before initializing monaco-vim and call preventDefault() on it. monaco-vim will ignore such events and won't do anything. This can be useful if you want to handle events like running code on CTRL/CMD+Enter which otherwise would have been eaten up by monaco-vim. (Available from v0.0.14 onwards).

AMD

If you are following the official guide and integrating the AMD version of monaco-editor, you can follow this -

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>

<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
<div id="status"></div>

<script src="https://unpkg.com/monaco-editor/min/vs/loader.js"></script>
<script>
  require.config({
    paths: {
      'vs': 'https://unpkg.com/monaco-editor/min/vs',
      'monaco-vim': 'https://unpkg.com/monaco-vim/dist/monaco-vim',
    }
  });
  require(['vs/editor/editor.main', 'monaco-vim'], function(a, MonacoVim) {
    var editor = monaco.editor.create(document.getElementById('container'), {
      value: [
        'function x() {',
        '\tconsole.log("Hello world!");',
        '}'
      ].join('\n'),
      language: 'javascript'
    });
    var statusNode = document.getElementById('status');
    var vimMode = MonacoVim.initVimMode(editor, statusNode);

    // remove vim mode by calling
    // vimMode.dispose();
  });
</script>
</body>
</html>

See demo.js for full usage.

If you would like to customize the statusbar or provide your own implementation, see initVimMode's implementation in src/index.js.

Adding custom key bindings

Actual vim implementation can be imported as:

import { VimMode } from 'monaco-vim';

Defining ex mode command

// VimMode.Vim.defineEx(name, shorthand, callback);
VimMode.Vim.defineEx('write', 'w', function() {
  // your own implementation on what you want to do when :w is pressed
  localStorage.setItem('editorvalue', editor.getValue());
});

For advanced usage, refer codemirror. CodeMirror.Vim is available as VimMode.Vim;

This implementaion of VIM is a layer between Codemirror's VIM keybindings and monaco. There may be issues in some of the keybindings, especially those that expect extra input like the Ex commands or search/replace. If you encounter such bugs, create a new issue. PRs to resolve those are welcome too.

More Repositories

1

medium-draft

📝 A medium like Rich Text Editor built on draft-js with a focus on keyboard shortcuts.
JavaScript
1,728
star
2

monaco-themes

Themes to be used and generated with monaco-editor in web browser
JavaScript
341
star
3

medium-style-confirm

medium.com style confirm dialog
HTML
165
star
4

kattappa

A block based rich text editor.
JavaScript
106
star
5

monaco-ace-tokenizer

Syntax highlighting support for additional languages in monaco-editor
JavaScript
77
star
6

bitwiser

Bitwiser Jekyll theme
CSS
38
star
7

blurt

A javascript default alert() and prompt() replacement.
JavaScript
33
star
8

bitwiser-material

jekyll material theme
CSS
32
star
9

vscode-excalidraw

Excalidraw integration for vscode
TypeScript
31
star
10

monaco-emacs

Emacs keybindings for monaco-editor
TypeScript
25
star
11

react-sketchapp-boilerplate

A basic project to quickly get you up and running for creating a react-sketchapp
JavaScript
16
star
12

yapper

flask self learning blog.
Python
10
star
13

flask-web-starter-kit

Flask application with complete integration of gulp build system
HTML
10
star
14

react-ssr-example

Example Typescript React project with SSR
JavaScript
10
star
15

tvm

TV Show Manager is a chrome app that can be used to track your favorite TV shows
JavaScript
6
star
16

extractor

Python
6
star
17

codemirror-lsp

JavaScript
4
star
18

Jekyll-Read

Yet another jekyll theme.
CSS
4
star
19

hello-world-tutorial

Frontend hello world tutorial with webpack
JavaScript
4
star
20

draft-text-editor-tutorial

Source code of the draft-js-text-editor tutorial
JavaScript
4
star
21

querybuilder

Python
3
star
22

monaco-playground

Demo page for monaco themes/vim/emacs/syntax highlighting
JavaScript
2
star
23

automate-github-trending

Send email notification of Github's trending repositories
Python
2
star
24

medium-blog

JavaScript
1
star
25

python-automplete-server

An autocomplete server for python source code
Python
1
star