npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-codemirror-electron

v3.0.7

Published

Codemirror component for Vue2 Electron package

Readme

This repository has been specially modified to be used with Electron Vue Starter Pack for using runtime Vue compiler.

GitHub issues GitHub forks GitHub stars Twitter

NPM NPM

Vue-Codemirror

Codemirror component for Vue2.

Build by Codemirror.

Example

Demo Page

Update

The latest version of the update, I hope the component itself is a simple and lightweight editor, in addition to the codemirror core library itself, without an other package; of course, it is still can automatically identify the language and theme package, and optimized; if you need other functions, you need to import the corresponding some resources package(with codemirror) in entrance script file or component script.

Most of the native codemirror component built-in event, and converted to a emit Vue event mechanism, if you need more complex event, please on method to get the codemirror component instance object to monitor, the following is a list of the converted event:

  • changes
  • beforeChange
  • cursorActivity
  • keyHandled
  • inputRead
  • electricInput
  • beforeSelectionChange
  • viewportChange
  • swapDoc
  • gutterClick
  • gutterContextMenu
  • focus
  • blur
  • refresh
  • optionChange
  • scrollCursorIntoView
  • update

component event list:

  • ready
  • change

Use Setup

Install vue-codemirror

npm install vue-codemirror --save

Vue use

// import
import Vue from 'vue'
import VueCodeMirror from 'vue-codemirror'


// or require
var Vue = require('vue')
var VueCodeMirror = require('vue-codemirror')


// global use
Vue.use(VueCodeMirror)


// if you need to custom new mode
VueCodeMirror.CodeMirror.defineMode('mymode', () => {
  return {
    token(stream, state) {
      if (stream.match("aaa")) {
        return "style1"
      } else if (stream.match("bbb")) {
        return "style2"
      } else {
        stream.next()
        return null
      }
    }
  }
})

// If you need to implement more features, such as the Lint mode code tip, you need to introduce a package that you will be relying on before the Vue program is instantiated, such as:
require('codemirror/addon/selection/active-line.js')
require('codemirror/addon/selection/mark-selection.js')
// require more resource...


// or use with component
import { codemirror, CodeMirror } from 'vue-codemirror'

// custom new mode
CodeMirror.defineMode('mymode', () => {
  // your mode code...
})

export default {
  components: {
    codemirror
  }
}

Use in component

<template>
  <!-- Bidirectional data binding(双向数据绑定) -->
  <codemirror v-model="code" :options="editorOptions"></codemirror>

  <!-- or to manually control the datasynchronization(或者手动控制数据流,需要像这样手动监听changed事件) -->
  <codemirror ref="myEditor"
              :code="code" 
              :options="editorOptions"
              @ready="onEditorReady"
              @focus="onEditorFocus"
              @change="onEditorCodeChange">
  </codemirror>
</template>

<script>
// Similarly, you can also introduce the resource pack you want to use within the component
// require('codemirror/some-resource')
export default {
  data () {
    return {
      code: 'const a = 10',
      editorOptions: {
        // codemirror options
        tabSize: 4,
        mode: 'text/javascript',
        theme: 'base16-dark',
        lineNumbers: true,
        line: true,
        // sublime、emacs、vim三种键位模式,支持你的不同操作习惯
        keyMap: "sublime",
        // 按键映射,比如Ctrl键映射autocomplete,autocomplete是hint代码提示事件
        extraKeys: { "Ctrl": "autocomplete" },
        // 代码折叠
        foldGutter: true,
        gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
        // 选中文本自动高亮,及高亮方式
        styleSelectedText: true,
        highlightSelectionMatches: { showToken: /\w/, annotateScrollbar: true },
        // more codemirror config...
        // 如果有hint方面的配置,也应该出现在这里
      }
    }
  },
  methods: {
    onEditorReady(editor) {
      console.log('the editor is readied!', editor)
    },
    onEditorFocus(editor) {
      console.log('the editor is focus!', editor)
    },
    onEditorCodeChange(newCode) {
      console.log('this is new code', newCode)
      this.code = newCode
    }
  },
  computed: {
    editor() {
      return this.$refs.myEditor.editor
    }
  },
  mounted() {
    console.log('this is current editor object', this.editor)
    // you can use this.editor to do something...
  }
}
</script>

Editor options mode types:

编辑器的模式(mode属性)分为 字符串、对象两种方式,可以在下面的相关链接中找到语言列表

// string mode(MIME types/字符串方式)
mode: 'text/javascript'

// or object mode(对象方式)
mode: {
  // name
  name: 'javascript',
  json: true,

  // or ext
  ext: 'js',

  // or mime
  mime: 'text/javascript',

  // or filename
  filename: 'index.js'
}

More options

Author Blog

Surmon