Changing Vi/Vim cursor style on active editor without vimrc

112 Views Asked by At

It is not always applicable to prepare such resource/config files as they are out of control (docker, remote, or someone else's system), so I need to do this inside the editor.

With all the information pile made for "add this to vimrc/shell", I am having a difficulty to find a solution.

Is it possible to change the cursor style for the active session/editor without touching any resource/config file? If so, how?


What have I tried:

My attempts lead me to solutions made only for resource/config files for vi/vim and/or shells. I don't know what exact search terms shall I use to get close to a result if any.


EDIT: Knowing how to "use Vi(m) to edit" files does not necessarily mean/imply you know how to set it up. Settings are some whole new level to learn advanced Vi/m. "Copy-paste" resources show one way, but fail to explain the WHY part.


EDIT: Thanks to commenters, I got the courage to try with more keen eyes and got my solution posted. Better explanations are welcome.

1

There are 1 best solutions below

0
Yılmaz Durmaz On

Until today, I believed it is guicursor that changes cursor style. I still do not know what it changes but this explains why I was failing.

Yet, it seems the cursor is directly related to the shell used, and then t_SI, t_EI, and t_SR are responsible to tell the shell which one to use and when.

With "my preference" explained on the right side comments, these 3 are the way to set cursor style.

:let &t_EI="\e[1 q"  " normal mode  - blinking block on character
:let &t_SI="\e[5 q"  " insert mode  - blinking bar on left(i) or right(a)
:let &t_SR="\e[2 q"  " replace mode - no-blink block on character

The \e part of the commands might need to change depending on the shell. some require it to be \<ESC> as in "\<ESC>[1 q"

The numbers here are: 1/2 for blinking/steady block, 3/4 for blinking/steady underline, and 5/6 for blinking/steady vertical bar


Also, as an extra, if the selection in visual mode is not readable, this should help:

:highlight Visual cterm=reverse ctermbg=none ctermfg=none


@romainl, thanks for "Everything you can do in your vimrc can be done manually in Vim's command-line"