question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle delay when exiting into vim normal mode

See original GitHub issue

Hello, @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]timeoutlens, but I don’t believe both of them are possible, are they?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
marskarcommented, Sep 29, 2020

@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.

0reactions
randy3kcommented, Aug 19, 2020

Your observation is correct. It is exactly how prompt toolkit handles the key bindings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vim - delay when exiting visual mode - Super User
If I press ESC to exit Visual Mode after I select some text, there's a noticeable delay before the text gets unselected and...
Read more >
How to exit visual mode without a delay in Vim? - Stack Overflow
Since I don't like pressing <C-c> to exit any mode, I currently map <ESC> to <C-c> in visual mode. This exits visual mode...
Read more >
Slow vim escape from insert mode - Vi and Vim Stack Exchange
There are two kinds of delay when you press <esc> in insert mode: ... This kind of delay is normal, you can change...
Read more >
term.txt - Vim
On very slow systems this may fail, causing cursor keys not to work sometimes. If you discover this problem reset the 'timeout' option....
Read more >
Convincing Xcode to Map Vim Keys - Bryce Pauken
Background; Finding Xcode's Vim Mode Implementation; Finding Input Handling Logic; Where to Hook; Making an Xcode Plugin ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found