Handle delay when exiting into vim normal mode
See original GitHub issueHello, @randy3k! I wanted to share my problem, its current workaround, and ask for any suggestions and possibilities of new radian settings.
By default, when using "vim"
editing mode there is a rather long delay when exiting from insert into normal mode after hitting <Esc>
key. It is tolerable if no radian.escape_key_map
is defined and long otherwise.
I believe, it is present in order to enable escape_key_map
functionality. However, I use those keymappings with <Alt>
key so I don’t really need any delay when hitting <Esc>
. I didn’t find any setting in radian which can help with this.
My current workaround is as follows. As radian uses Python’s ‘prompt_toolkit’, there is a way to modify that delay. Currently it is defined by ttimeoutlen
and timeoutlen
properties of Application
class. Their default values are 0.5 and 1 seconds. After experimenting, it seems that delay of 0.5 is “used” when no escape_key_map
is defined and 1.5 (0.5+1) otherwise. Inspired by this comment, I implemented the following workaround (which is added to ‘.radian_profile’):
options(
radian.editing_mode = "vim",
radian.on_load_hooks = list(function() {
getOption("rchitect.py_tools")$attach()
radian <- import("radian")
app <- radian$get_app()$session$app
# Modify timeout lengths (in seconds): time to wait after pressing <Esc>
# for another key pressing. Very useful to reduce delay when going in
# Normal mode under "vim" editing mode.
app$ttimeoutlen <- 0
# This shouldn't be too small, as it is used when dealing operator sequence
# in normal mode
app$timeoutlen <- 0.25
})
)
Currently this works for me. Is there any chance of getting “official” radian settings which can help with this issue? The ultimate solution would be two settings: enabling <Alt>
key mappings instead of <Esc>
and those [t]timeoutlen
s, but I don’t believe both of them are possible, are they?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top GitHub Comments
@echasnovski, your solution is great. I was going to do something similar to change the cursor shape based on the current vim mode, but I decided to edit the Python code instead of writing an R hook in an
option ()
call. I submitted a PR (#222) that changes both the cursor shape and[t]timeoutlens
. You can find more info in the issue (#220) that preceded the PR.Your observation is correct. It is exactly how prompt toolkit handles the key bindings.