[Resolved] Changing cursor style depending on mode

Is there a way? In vim I was used to that extra bit of feedback as to which mode I was in based on if I had a block cursor (normal) or vertical line (insert). Perhaps related would be the ability to turn on blinking of the cursor, although I don’t mind it remaining solid as much as I thought I might have.

On the other hand, I’m not sure how much control kak has over how the cursor is drawn if running inside tmux…

Vertical line cursor in Kakoune would be misleading as Kakoune always operate on selection, and “just cursor” is a selection of the current character, and there is no 0-width selection in Kakoune.

One of the options (which I use) is to change cursor color in insert mode, like this:

hook global ModeChange insert:.* %{
    set-face global PrimaryCursor      rgb:ffffff,rgb:000000+F
}

hook global ModeChange .*:insert %{
    set-face global PrimaryCursor      rgb:ffffff,rgb:008800+F
}
4 Likes

This is exactly the sort of answer I was hoping for! I can accept the selection logic, and color will serve my purposes.

The answer is out of date as 2021.09.03.

I had to change these modifications to make it work:

hook global ModeChange (push|pop):insert:.* %{
    set-face global PrimaryCursor      rgb:ffffff,rgb:008800+F
}

hook global ModeChange (push|pop):.*:insert %{
    set-face global PrimaryCursor      rgb:ffffff,rgb:880000+F
}
4 Likes

If you use multiple windows, you have to replace global to window inside the hook so that the color change only happens in the actual window where insert mode is entered.

This is what I have in my colorscheme file:

# Define custom faces to keep them organized
set-face global PrimaryCursorNormal +r
set-face global PrimaryCursorInsert bright-magenta+r
set-face global PrimaryCursor PrimaryCursorNormal

# EOL cursor
set-face global PrimaryCursorEolNormal default,bright-cyan
set-face global PrimaryCursorEolInsert PrimaryCursorInsert
set-face global PrimaryCursorEol PrimaryCursorEolNormal


# [...]

hook global ModeChange (push|pop):.*insert %{
	set-face window PrimaryCursor PrimaryCursorInsert
	set-face window PrimaryCursorEol PrimaryCursorEolInsert
}

hook global ModeChange (push|pop):insert:.* %{
	set-face window PrimaryCursor PrimaryCursorNormal
	set-face window PrimaryCursorEol PrimaryCursorEolNormal
}

Edit: Added faces for PrimaryCursorEol

You can set the cursor to _ on insert mode.

# set cursor to underline
hook global InsertIdle .* %{
  set-face window PrimaryCursor default,default+u
  set-face window PrimaryCursorEol default,default+u
  set-face window SecondaryCursor default,default+u
  set-face window SecondaryCursorEol default,default+u
  set-face window LineNumberCursor default,default+u
  set-face window PrimarySelection default,default+u
  set-face window SecondarySelection default,default+u
}

# set cursor to default
hook global NormalIdle .* %{
  set-face window PrimaryCursor default,default+r
  set-face window PrimaryCursorEol default,default+r
  set-face window SecondaryCursor default,default+r
  set-face window SecondaryCursorEol default,default+r
  set-face window LineNumberCursor default,default+r
  set-face window PrimarySelection default,default+r
  set-face window SecondarySelection default,default+r
}

Insert
insert

Normal
normal