Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor shape changes briefly when space bar pressed #45

Open
echristopherson opened this issue Jan 17, 2016 · 5 comments
Open

Cursor shape changes briefly when space bar pressed #45

echristopherson opened this issue Jan 17, 2016 · 5 comments

Comments

@echristopherson
Copy link

I use t_SI and t_EI to change the shape of my cursor when entering insert or normal modes. I notice that with lexima active, the cursor shape changes perceptibly whenever I hit the space bar in insert mode. I assume lexima is entering and exiting normal mode behind the scenes. I don't know if it's feasible, but it would be nice if this didn't happen perceptibly.

@cohama
Copy link
Owner

cohama commented Feb 2, 2016

Thank you for reporting. I want to try cursor shape behavior but I'm poor at the terminal.
Please teach me what terminal emulator can be used and how to set t_Sl and t_El.

@echristopherson
Copy link
Author

I'm really sorry for the delay.

I use iTerm 2 on OS X. In my vimrc I have:

let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"

tmux has its own escape codes for these; it translates them into something the real terminal emulator understands (if it understands any such code). For that case, I have:

let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"

There are other terminals (I think probably at least Konsole and GNOME Terminal) that support it, but the exact escape sequence varies somewhat.

The first of those is automatically sent by Vim when entering insert mode; the latter when leaving it. The quick shape changes I mention happen since your plugin leaves insert mode briefly when certain keys are pressed. I'm not sure there's much that can be done about it, honestly; even makes the shape change.

@jonsmithers
Copy link

jonsmithers commented Aug 18, 2019

In my own experiments, I discovered that adding <silent> to the mapping of <space> introduces this behavior. Remove the <silent> and the cursor goes back to looking normal when you hit space bar (but then vim displays the function that gets called at the bottom).

Also, I only see this issue in vim 8.1-1790, not neovim 0.3.8, and not gvim.

(tested on linux with the following settings):

let &t_SI = "\e[6 q"
let &t_EI = "\e[2 q"
let &t_SR = "\e[3 q"

@jonsmithers
Copy link

jonsmithers commented Aug 18, 2019

One workaround I've discovered is to :redraw on the first line of the function invoked with <c-r>=.

I don't know what :redraw entails, but it sounds a bit inefficient.

demo code:

inoremap <silent> <space> <c-r>=Space()<cr>
fun! Space()
  call s:HideVimCursorSpasm()
  return ' '
endfun
fun! s:HideVimCursorSpasm()
  if !has('nvim') && !has('gui_running') | redraw | end "hide cursor spasm that only occurs in vim
endfun

@jonsmithers
Copy link

I don't think the aforementioned workaround works on iTerm in macos.

I think a better solution is to remove <silent> from the mapping and just echo '' at the beginning so it seems like it's a silent mapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants