noib3/nvim-oxi

keymapping binding to a function

zdcthomas opened this issue · 2 comments

Hi!
First off, love the crate, I'm currently using it to put together a fairly large plugin, and I was wondering if there was an easy way to map a key to a rust function? If not I'd love to help implement that!

Thanks!

Yes, same as in Lua.

use nvim_oxi::api::{self, opts::SetKeymapOpts, types::Mode};

#[nvim_oxi::plugin]
fn foo() {
    let opts = SetKeymapOpts::builder()
        .callback(|()| nvim_oxi::print!("Hello!"))
        .build();

    api::set_keymap(Mode::Normal, "p", "", &opts).unwrap();
}

If you want the mapping to be buffer-local, use Buffer::set_keymap() instead.

amazing! I guess I've been too spoiled by keymap.set to remember!