Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: In Terminal, how can I have a better cursor?

I've noticed when I use the Terminal that the cursor is not as I configured it.

In other words, in the GUI it looks perfect, the cursor that is, but in the Terminal it takes time to update, it doesn't look like I configured it etc.

Here are my settings for the cursor:

set guicursor=n-v-c:block-Cursor-blinkon0
set guicursor+=ve:ver35-Cursor
set guicursor+=o:hor50-Cursor-blinkwait175-blinkoff150-blinkon175
set guicursor+=i-ci:ver20-Cursor
set guicursor+=r-cr:hor20-Cursor
set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175

I do notice it's called the guicursor setting, however in Terminal some of these do take effect, they just don't take a full effect.

Also, it seems the cursor doesn't get updated a lot. For example if I enter insert mode the correct cursor is put, but if I get out, the same cursor is used until I move or something then it updated to the normal mode cursor.

Do you have any tips on this? Or do I just have to bear with it?

EDIT:

My OS is a Mac Mini with Mountain Lion installed. I am using iTerm2 with xterm-color256 as the Terminal.

Re-wording the question: How can I make the cursor redrawing faster in a Terminal and how can I make it take the settings I put above? I already tried ttyfast and lazyredraw.

like image 630
greduan Avatar asked Dec 25 '12 13:12

greduan


People also ask

How do I change my cursor to insert mode?

Press the Insert key on your keyboard to switch back to insert mode.

How do I highlight a cursor in Vim?

Simply putting :set cursorline in your vimrc will highlight the current line in every window and update the highlight as the cursor moves. With the default backslash leader key, typing \c will toggle highlighting on and off. That makes it easy to locate the cursor after scrolling in a large file.


2 Answers

Your settings are for GUI Vim. You can't expect them to work in CLI Vim. If you don't like how CLI Vim works, just use MacVim.

I've got a slightly different version of this function executed in my ~/.vimrc:

" changes the cursor shape/color
" in the terminal depending on the mode
" see http://code.google.com/p/iterm2/issues/detail?id=710&q=cursor
function! SetCursorStyle()
  if &term =~ "xterm\\|rxvt"
    " use a | cursor in insert mode
    let &t_SI = "\<Esc>]50;CursorShape=1\x7"

    " use a rectangle cursor otherwise
    let &t_EI = "\<Esc>]50;CursorShape=0\x7"

    " reset cursor when vim exits
    autocmd VimLeave * silent !echo -ne "\<Esc>]50;CursorShape=0\x7"

  endif
endfunction
like image 81
romainl Avatar answered Sep 21 '22 10:09

romainl


I use Cygwin, and I use the above setting but Cygwin's xterm may can't recognize the "\]50;CursorShape=1\x7"

So I try this one, and it work

if &term =~ "xterm\\|rxvt"
  " use a | cursor in insert mode
  let &t_SI = "\<Esc>[5 q"

  " use a rectangle cursor otherwise
  let &t_EI = "\<Esc>[1 q"
endif

then, I add this to .bashrc to change the term cursor to block, and it perfect to me.

# change cursor to blinking block
echo -ne "\x1b[1 q"
like image 40
SenZhang Avatar answered Sep 22 '22 10:09

SenZhang