59

I am used to having a block cursor in normal mode in Vim. This makes sense with the Vim paradigm; when you press x, it is clear which character will be deleted.

I've installed Cygwin on a Windows computer, but when I use Vim in its terminal, I get the I cursor, even in normal mode. How can I make the cursor be a block instead?

Kazark
  • 3,419
  • 3
  • 26
  • 35

5 Answers5

91

This question on the Cygwin mailing list answers the question by setting some arcane variables to the appropriate escape sequences. Add this to your .vimrc:

let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
Kazark
  • 3,419
  • 3
  • 26
  • 35
  • 3
    this worked for me when using mintty to ssh to a linux server – zzapper Apr 15 '14 at 12:41
  • 2
    Thank you so much. Gotta love a clean solution that works in 2 most annoying cases :) – rld. Jun 08 '14 at 05:58
  • 4
    Nice. Unfortunately, in ConEmu this affects the cursor for the entire session. That said, it works as expected in vim. It also works fine in cygwin's terminal emulator. But, who uses that? ;) – George Marian Aug 17 '16 at 15:44
  • 2
    Almost perfect... but when leaving insert mode, it returns to a line cursor until you move the cursor in some direction. – Joe Coder Jun 12 '17 at 15:55
  • 1
    Worked for me in the version of Vim installed automatically with Cmder. Thank You! – Bangash Jun 16 '17 at 14:03
  • 1
    Worked for me in git bash on windows (mysys2) as well! – Kevin Tighe Oct 18 '17 at 13:18
  • @GeorgeMarian : Just being curious: What is the _cygwin terminal emulator_? I am using mintty and ConEmu for Cygwin. Is there anything else available? – user1934428 Jul 07 '21 at 11:37
  • 1
    you can add the lines ```set ttimeout set ttimeoutlen=1 set listchars=tab:>-,trail:~,extends:>,precedes:<,space:. set ttyfast ``` to make it switch quicker see https://stackoverflow.com/a/58042687/1766242 – maninvan Jul 21 '21 at 09:25
  • 1
    I'm running ubuntu on WSL2. This worked for me as well. Thanks! – Prasanna Jan 14 '22 at 17:34
  • Worked in a recent Git Bash Windows 10 install without the other problem reported here. – NeilG Nov 19 '22 at 03:41
38

There's a setting for that, in the cygwin terminal emulator:

Right-click on the window title bar > Options > Looks > Cursor > Cursor radio button

Johnny Hoang
  • 516
  • 3
  • 3
  • To complete, this kind of options are the same as any other windows terminal window, which cygwin is. – mveroone Aug 22 '13 at 09:35
  • 8
    Pro: my `.vimrc` can be more compatible with my Linux or Windows `.vimrc`. Con: now I have the block cursor in insert mode, when I wanted the `I` cursor in that mode. +1 – Kazark Aug 22 '13 at 13:21
  • 6
    the question was asking about controlling the cursor in VIM but this answer affects the cursor for the entire shell session, both at the command prompt and in VIM – David Alpert Jan 15 '16 at 16:09
  • my vim is plain text - click? bar? what bar? – Ed Randall Jun 10 '16 at 14:14
  • 1
    @EdRandall this is a question about the Cygwin terminal AND vim. This answer pertains to the Cygwin side of the question. – shmup Jul 14 '16 at 19:57
  • 1
    This doesn't answer the question completely. [Vim uses 2 types of cursors.](http://superuser.com/questions/634326/how-can-i-get-a-block-cursor-in-vim-in-the-cygwin-terminal/635194#635194) In normal, visual, or command mode it's a block. In insert mode, it's a vertical bar. These instructions are for a wholesale change in a specific terminal emulator (cygwin), though most should have something similar. So, it affects the cursor everywhere in the terminal, and, more importantly, it doesn't mimic vim's cursor functionality. – George Marian Aug 17 '16 at 15:35
  • It's been noted that this affects the entire shell session. For me, Vim seemed to be inheriting that shell session cursor format. Modifying Vim settings alone didn't help. Changing the option as suggested in this post did. – Mike Jan 27 '17 at 13:33
  • @DavidAlpert The question is about vim _in Cygwin_. This answers the question. It may not be ideal because it affects other programs, BUT, as a Cygwin user, there is a good chance that that is what you're looking for when you find this page. (I was.) I agree this kind of answer would be a bad answer if the platform was Linux, but in this case it may be what users are looking for. – felwithe Oct 07 '19 at 14:57
  • I don't think it changes the cursor type to vertical when we are in the insert mode. I am getting a block cursor all the time in cygwin now, even if I am in the insert mode in vim. – humble Dec 21 '19 at 04:07
4

Create a file ~/.minttyrc, add below line to it

CursorType=block

Then re-launch mintty, which is Cygwin's default terminal.

qeatzy
  • 285
  • 2
  • 12
0

Or, you could create a batch file:

 %SYSTEMDRIVE%\cygwin\bin\mintty.exe ^
        -s 132,50 -o ScrollbackLines=10000 ^
        -o BackgroundColour=54,54,54 ^
        -o Transparency=High -o OpaqueWhenFocused=yes ^
        -o CursorColour=Green -o CursorType=block -o CursorBlinks=no ^
        -o Font=Consolas -o FontHeight=10 ^
        /bin/env CHERE_INVOKING=1 /bin/bash -l -i

And run it.

If you don't like the blinking cursor in the DOS command windows too use %COMSPEC% instead of /bin/env/... and be surprised.

Andreas Spindler
  • 249
  • 1
  • 3
  • 10
0

People have raised the issue of @Kazark's answer setting the cursor for the entire shell session, to set it back to a line there are a couple of things you can do:

In .vimrc:

autocmd VimLeave * silent let &t_te.="\e[5 q"

Which should set in when you leave vim but it's not flawless (in particular when I'm running tmux on Windows and on a Linux machine I'm connected to), you can issue:

 printf '\033[5 q' 

at the command prompt.

Hipponax43
  • 156
  • 3