Found a related discussion.
cnorm
on my machine is
\E[?25h\E[?0c
The tail \E[?0c
will always reset cursor shape.
I thought I can use t_SI
and t_EI
if I remove it from cnorm
(it's termcap
code is ve
):
let &t_ve= "\e[?25h"
let &t_SI = "\e[?0;c"
let &t_EI = "\e[?6;c"
But I can't see my cursor after executing above commands, looks like one has to set cursor shape in t_ve
in text console(see update)?
I guess I can do it with autocmd
:
augroup ag_tc_cursor | au!
autocmd WinEnter,InsertLeave,CmdlineLeave * let &t_ve= "\e[?25h\e[?112c"
autocmd InsertEnter,CmdlineEnter * let &t_ve= "\e[?25h\e[?0c"
augroup end
This will use blinking underscore cursor in insert or cmdline mode, static full block cursor in normal mode.
The character under cursor won't look clearly unless it's white, that basically make it useless(see update)?
If you want to change cursor for all applications, you can change cnorm and recompile terminfo.
Update, get black on white static soft cursor
According to Software cursor for VGA, current cell color is controlled by a 8 bit color byte:
7 6 5 4 3 2 1 0
blink bg_red bg_green bg_blue bold fg_red fg_green fg_blue
Soft cursor escape sequence has 3 parameters (first one fixed to 16?):
<ESC>[?16;{toggle_bits};{select_bits}c
After some experiment, I believe the cursor color is defined as:
(current_color | select_bits) ^ toggle_bits
In order to get static black on white, we must make sure the final color byte is always 0 111 0 000
in binary no matter what current_color
is.
We can set both the select_bits and toggle_bits to set it to 0 ( (x | 1) ^ 1 = 0
), set select_bits only to set it to 1 ( (x | 1) ^ 0 = 1
):
select_bits = 0B11111111 = 255
toggle_bits = 0B10001111 = 143
Put everything together:
augroup ag_tc_cursor | au!
autocmd WinEnter,InsertLeave,CmdlineLeave * let &t_ve= "\e[?25h\e[?16;143;255c"
autocmd InsertEnter,CmdlineEnter * let &t_ve= "\e[?25h\e[?0c"
augroup end
Update, remove autocmd, use t_SI, t_SE
It's a total mistake to do this by autocmd
, InsertEnter
won't be triggered by r
.
For whatever reason, vim send t_vi
upon InsertLeave
, t_vi
in linux
defauts to:
\E[?25l\E[?1c
It hide cursor and set cursor shape to invisible (I have no idea why would it do that) .
That's why you can't see the cursor if you change only t_ve
to "\e[?25h"
, to fix it, you must remove the cursor shape escape sequence ("\E[?1c"
) from t_vi
.
Put everything together:
let &t_ve= "\e[?25h"
let &t_vi= "\e[?25l"
let &t_SI= "\e[?0c"
let &t_EI= "\e[?16;143;255c"