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.

vi mode-dependent cursor shape

See original GitHub issue

I would like radian to have a beam cursor (|) in vi insert mode and a block cursor in vi navigation (normal) mode.

Since both radian and IPython use prompt-toolkit, I think it will be helpful to link to the relevant prompt-toolkit issue. By including the code from the issue in my ipython_config.py file, i was able to set up IPython with a vi mode-dependent cursor:

  • Insert: image
  • Navigation: image

How could I do something similar in my .radian_profile?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
mskarcommented, Sep 29, 2020

Wow, I just pasted the relevant code from my ipython_config.py into radian/settings.py and it works! 😄

image image image

Is settings.py the right place for it? Or is it better for this to be handled by a config file?

Should I submit a pull request? I think everyone who uses the radian vi mode will want this.

import sys

from prompt_toolkit.application.current import get_app
from prompt_toolkit.key_binding.vi_state import InputMode, ViState


def get_input_mode(self):
    if sys.version_info[0] == 3:
        # Decrease input flush timeout from 500ms to 10ms.
        app = get_app()
        app.ttimeoutlen = 0.01
        app.timeoutlen = 0.2

    return self._input_mode


def set_input_mode(self, mode):
    shape = {InputMode.NAVIGATION: 2, InputMode.REPLACE: 4}.get(mode, 6)
    cursor = "\x1b[{} q".format(shape)

    if hasattr(sys.stdout, "_cli"):
        write = sys.stdout._cli.output.write_raw
    else:
        write = sys.stdout.write

    write(cursor)
    sys.stdout.flush()

    self._input_mode = mode

ViState._input_mode = InputMode.INSERT
ViState.input_mode = property(get_input_mode, set_input_mode)
1reaction
YlanAllouchecommented, Oct 5, 2020

Hey @mskar,

Thanks a lot for detailed steps. The issue was my terminal forcing a cursor shape on top of radian. This now works for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change cursor shape depending on VI mode in Bash?
SOLUTION: I am posting my answer to my own question here as recommended. This solution works for Bash 4.4+, since, starting with that ......
Read more >
Configuring the cursor - Vim Tips Wiki - Fandom
Using gvim with the defaults, the cursor shape is a block when in n-v-c modes (normal mode, or visual selection mode, or command...
Read more >
How to make the cursor shape dependent on the current Vim ...
How to make the cursor shape dependent on the current Vim mode using iTerm2 on OS X and zsh. Save this question. Show...
Read more >
Change Your Vim Cursor from a Block to Line in ... - YouTube
A multi-terminal compatible way to switch your Vim cursor depending on which mode you're in.Hit the subscribe button to receive more videos ...
Read more >
Change Your Vim Cursor from a Block to Line ... - Nick Janetakis
This is a huge quality of life enhancement if you're using terminal Vim. Without this it's tricky to tell if you're within insert...
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