Vim - How to use defineEx()


I’m having a little trouble with defining my own ex commands with the vim API. This should be simple, I think, but I don’t really understand what arguments exactly to pass and how to pass them to the function. I tried “name : ct, prefix : undefined” too, but that also resulted in:
"Not an editor command: “ct”

Here’s my current attempt at getting it running:

defineEx(ct, undefined, vim_custom_ct(myCodeMirror));

function vim_custom_ct(cm) {

If someone knows how to use this function properly, please let me know!

The third argument should be a function, whereas you’re currently giving it the result of calling vim_custom_ct, which is undefined. Try defineEx(ct, undefined, vim_custom_ct)

Thanks a lot for your reply. :smile:

Unfortunately, passing on the function like you described also results in the “not an editor command” error.

What’s in ct? Are you passing a string as first argument and actually using that same string to run the command?

Oh this is embarassing. I was passing an undefined variable when I was intending to pass ct as a string…

Fixed it to

defineEx("ct", undefined, vim_custom_ct);

but I still get the same error when typing :ct

edit: Got it. I was missing the object to call the function on. It works now.