Maximus5 / ConEmu

Customizable Windows terminal with tabs, splits, quake-style, hotkeys and more
https://conemu.github.io/
BSD 3-Clause "New" or "Revised" License
8.59k stars 572 forks source link

Is it possible to change cursor in vim depending on the mode? #1781

Open asolopovas opened 5 years ago

asolopovas commented 5 years ago

Hi,

I am trying to have cursor change to a Vertical Line in insert mode and to Block in normal mode. But could not find any info on how to do that in ConEmu. I managed to do so in putty by setting cursor appearance to vertical line and adding

" Insert Mode
let &t_SI .= "\e[=1c"
" Normal Mode
 let &t_EI .= "\e[=2c"

But same doesn't work in ConEmu and openssh. Is there a way to do that?

Maximus5 commented 5 years ago

You may change the shape of the cursor https://conemu.github.io/en/AnsiEscapeCodes.html#Terminal_modes

asolopovas commented 5 years ago

I have tried the following it just seems to be ignored

 "Con Emu--------------------------
   " Insert Mode
   let &t_SI .= "\<Esc>[5 q"
   " Normal Mode
   let &t_EI .= "\<Esc>[1 q"

It simply stays as vertical blinking line no matter what I do.

Maximus5 commented 5 years ago

What is your vim from and hub how do you run it?

asolopovas commented 5 years ago

My vim is 8.1.549, I am running it on centos vps, when I connect to it directly via putty it works without problem, but if I do the same via openssh on conemu the cursor remains unchanged no matter what spent days trying to figure it out. But nothing seems to work.

LesterCovax commented 5 years ago

I'd first run :set term (to show you current term type) and :set termcap (to see if t_SI and t_EI are actually set) in VIM, from both putty and conemu. The escape sequences below that I found match up with the second set you gave, so I'd guess that you have putty running in xterm mode, but xterm isn't enabled in ConEmu's settings.

if &term =~ '^xterm\|rxvt'
    " solid underscore
    let &t_SI .= "\<Esc>[4 q"
    " solid block
    let &t_EI .= "\<Esc>[2 q"
    " 1 or 0 -> blinking block
    " 3 -> blinking underscore
    " Recent versions of xterm (282 or above) also support
    " 5 -> blinking vertical bar
    " 6 -> solid vertical bar
endif
if &term =~ "xterm"
    let &t_SI = "\<Esc>[6 q"
    let &t_SR = "\<Esc>[4 q"
    let &t_EI = "\<Esc>[2 q"
endif

Source: http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes

(From comp.editors, by Juergen Weigert, in reply to a question)

:> Another question is that after exiting vim, the screen is left as it :> was, i.e. the contents of the file I was viewing (editing) was left on :> the screen. The output from my previous like "ls" were lost, :> ie. no longer in the scrolling buffer. I know that there is a way to :> restore the screen after exiting vim or other vi like editors, :> I just don't know how. Helps are appreciated. Thanks. : :I imagine someone else can answer this. I assume though that vim and vi do :the same thing as each other for a given xterm setup.

They not necessarily do the same thing, as this may be a termcap vs. terminfo problem. You should be aware that there are two databases for describing attributes of a particular type of terminal: termcap and terminfo. This can cause differences when the entries differ AND when of the programs in question one uses terminfo and the other uses termcap (also see |+terminfo|).

In your particular problem, you are looking for the control sequences ^[[?47h and ^[[?47l. These switch between xterms alternate and main screen buffer. As a quick workaround a command sequence like echo -n "^[[?47h"; vim ... ; echo -n "^[[?47l" may do what you want. (My notation ^[ means the ESC character, further down you'll see that the databases use \E instead).

On startup, vim echoes the value of the termcap variable ti (terminfo: smcup) to the terminal. When exiting, it echoes te (terminfo: rmcup). Thus these two variables are the correct place where the above mentioned control sequences should go.

Compare your xterm termcap entry (found in /etc/termcap) with your xterm terminfo entry (retrieved with "infocmp -C xterm"). Both should contain entries similar to: :te=\E[2J\E[?47l\E8:ti=\E7\E[?47h:

PS: If you find any difference, someone (your sysadmin?) should better check the complete termcap and terminfo database for consistency.

NOTE 1: If you recompile Vim with FEAT_XTERM_SAVE defined in feature.h, the builtin xterm will include the mentioned "te" and "ti" entries.

NOTE 2: If you want to disable the screen switching, and you don't want to change your termcap, you can add these lines to your .vimrc: :set t_ti= t_te=

kariem-ali commented 5 years ago

If you are using Vim with WSL, there was a known WSL issue https://github.com/Microsoft/console/issues/68. That issue was fixed in a recent Windows 10 update. However, I don't know if this fix will enable ConEmu to detect the cursor change from the "Real Console". Perhaps @Maximus5 can shed more light on that. More details and a hacky workaround here https://github.com/Maximus5/ConEmu/issues/937#issuecomment-446834709.

asolopovas commented 5 years ago

I am using vim on my centos vps. The cursor does change one I open host from putty, but not when usin powershell and openssh via conemu. In putty there is a trick you have to perform in order to make the cursor change is to set default cursor to vertical line rather than a block.

Here is my vim config, don't know where to look further.

This is my xterm termcap entry:

infocmp -C xterm
#       Reconstructed via infocmp from file: /usr/share/terminfo/x/xterm
xterm|xterm terminal emulator (X Window System):\
        :am:bs:km:mi:ms:xn:\
        :co#80:it#8:li#24:\
        :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
        :K2=\EOE:LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:\
        :UP=\E[%dA:ae=\E(B:al=\E[L:as=\E(0:bl=^G:bt=\E[Z:cd=\E[J:\
        :ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:cr=^M:\
        :cs=\E[%i%d;%dr:ct=\E[3g:dc=\E[P:dl=\E[M:do=^J:ec=\E[%dX:\
        :ei=\E[4l:ho=\E[H:im=\E[4h:is=\E[!p\E[?3;4l\E[4l\E>:\
        :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\E[15~:k6=\E[17~:\
        :k7=\E[18~:k8=\E[19~:k9=\E[20~:kD=\E[3~:kI=\E[2~:kN=\E[6~:\
        :kP=\E[5~:kb=\177:kd=\EOB:ke=\E[?1l\E>:kh=\EOH:kl=\EOD:\
        :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
        :me=\E[0m:mm=\E[?1034h:mo=\E[?1034l:mr=\E[7m:nd=\E[C:\
        :rc=\E8:\
        :..sa=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m:\
        :sc=\E7:se=\E[27m:sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:\
        :te=\E[?1049l:ti=\E[?1049h:ue=\E[24m:up=\E[A:us=\E[4m:\
        :vb=\E[?5h\E[?5l:ve=\E[?12l\E[?25h:vi=\E[?25l:\
        :vs=\E[?12;25h: