inkdropapp / inkdrop-vim

Provides Vim modal control for Inkdrop, blending the best of Vim and Inkdrop
https://www.inkdrop.app/
MIT License
101 stars 9 forks source link

How can I create Ex commands? #27

Closed ghost closed 3 years ago

ghost commented 3 years ago

I wanna create some ex commands to inkdrop commands like :f to core:find-global as I use in vim.

craftzdog commented 3 years ago

I'm afraid that Ex commands are hard-coded and can't be customized.

https://github.com/inkdropapp/inkdrop-vim/blob/master/src/vim.js#L958

ghost commented 3 years ago

Is there any alternatives to put some global object that is customizable through a cson file like keymaps?

craftzdog commented 3 years ago

You can write init.js like so:

inkdrop.onEditorLoad(() => {
    var CodeMirror = require('codemirror')
    CodeMirror.Vim.defineEx('find', 'f', (cm, event) => {
      inkdrop.commands.dispatch(document.body, 'core:find-global')
      if (event.argString) inkdrop.commands.dispatch(document.body, 'core:search-notes', { keyword: event.argString.trim() })
    })  
})
ghost commented 3 years ago

It worked! Thanks