radian: Keybind to exit vim mode and prompt indication format

I would like to map jj to exit insert mode (i.e switch to navigation mode). Is this possible?

Also can we format the text that indicates the current vi mode? Currently in the config I have:

options(radian.vi_mode_prompt = "\033[0;35m({})\033[0m")

and insert mode is shown as (ins). I would like to replace it by (I). Thanks in advance

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (10 by maintainers)

Most upvoted comments

I have just pushed d3bd041 which allows running user hooks.

Given that you have some experience of working with prompt-toolkit, try the following hook function.

options(radian.on_load_hooks = list(function() {
    getOption("rchitect.py_tools")$attach()

    radian <- import("radian")
    prompt_toolkit <- import("prompt_toolkit")

    KeyPress <- prompt_toolkit$key_binding$key_processor$KeyPress
    Keys <- prompt_toolkit$keys$Keys

    insert_mode <- radian$key_bindings$insert_mode
    app <- radian$get_app()
    kb <- app$session$modes$r$prompt_key_bindings

    kb$add("j", "j", filter = insert_mode)(function(event) {
        event$app$key_processor$feed(KeyPress(Keys$Escape))
    })
}))

Ultimately, I want to expose these things directly to R users, for example via an R package radianapi.

app$session$modes$r$prompt_key_bindings will only apply the keybindings to the regular R mode. Use app$session$modes$r$key_bindings if you want all the keys to be enabled in all modes.

You could use the following to get normal mode.

operator <- import("operator")
normal_mode <- operator$inv(radian$key_bindings$insert_mode)

By the way, if you want debug mode only keybindings, use app$session$modes$browse$prompt_key_bindings.