You are not logged in.

#1 2013-01-07 18:12:10

anonymous_user
Member
Registered: 2009-08-28
Posts: 3,058

rxvt-unicode and vim cursor shape

So I use rxvt as my terminal and when using vim, I want the cursor to change shape based on the current mode. I found this page which lists solutions for a few terminals, but none for rxvt:

http://vim.wikia.com/wiki/Change_cursor … rent_modes

I also found this page:

http://vim.wikia.com/wiki/Configuring_the_cursor

The first code:

if &term =~ "xterm\\|rxvt"
  " use an orange cursor in insert mode
  let &t_SI = "\<Esc>]12;orange\x7"
  " use a red cursor otherwise
  let &t_EI = "\<Esc>]12;red\x7"
  silent !echo -ne "\033]12;red\007"
  " reset cursor when vim exits
  autocmd VimLeave * silent !echo -ne "\033]112\007"
  " use \003]12;gray\007 for gnome-terminal
endif

Does indeed change the cursor color however that is not what I want. Furthermore, my cursor stays red after exiting vim. The second code:

if &term =~ '^xterm'
  " 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

Does not change my cursor in any discernable manner. I did modify the if of course; however, removing the if and just using the two let lines did not have any effect.

Here is my current Xresources:

! Black
*color0:   #000000
*color8:   #555753

! Red
*color1:   #cc0000
*color9:   #ef2929

! Green
*color2:   #4e9a06
*color10:  #8ae234

! Yellow
*color3:   #c4a000
*color11:  #fce94f

! Blue
*color4:   #3465a4
*color12:  #729fcf

! Magenta
*color5:   #75507b
*color13:  #ad7fa8

! Cyan
*color6:   #06989a
*color14:  #34e2e2

! White
*color7:   #d3d7cf
*color15:  #eeeeec

*foreground:       		#ffffff
*background:       		#000000

xterm*font:         	-*-terminus-medium-*-12-*
xterm*wideFont: 		-misc-fixed-medium-r-normal-ja-13-120-75-75-c-120-iso10646-1
xterm*saveLines:		2048

!URxvt.font: 			-dec-terminal-*-*-*-*-*-*-*-*-*-*-*-*
URxvt.font:         	-*-terminus-medium-*-12-*
!URxvt.font: 			xft:mono:size=9
URxvt.iconFile:			/usr/share/icons/Faenza/apps/scalable/utilities-terminal.svg
URxvt.scrollBar: 		off
!URxvt.cursorBlink:		true
!URxvt.cursorUnderline:	true
URxvt.perl-ext-common:  default,vtwheel

And my .vimrc:

:start
set nocompatible

set autoindent
set autoread
set backspace=indent,eol,start
set encoding=utf-8
set fileformats=unix,dos,mac
set gdefault
set history=50
set laststatus=2
set mouse=a
set nobackup
set nomodeline
set noruler
set number
set report=0
set statusline=[line:\ %l\ /\ %L]\ [col:\ %c]\ [mode:\ %{&ff}]\ [encoding:\ %{strlen(&fenc)?&fenc:'none'}]\ [filetype:\ %y]
set title
set viminfo=
set wildmenu
set wildmode=list:longest

" search
set ignorecase
set incsearch
set smartcase

" tabs
set shiftwidth=4
set smartindent
set tabstop=4

if has("gui_running")
   	colorscheme vibrantink
   	set guioptions-=tT
   	set guifont=Terminus\ 9
else
	if exists('$DISPLAY')
		set t_Co=256
		colorscheme vibrantink
	else
		colorscheme vividchalk
	endif
endif

let &t_SI .= "\<Esc>[4 q"
let &t_EI .= "\<Esc>[2 q"

filetype indent on
filetype plugin on
syntax on

And if it makes any difference, I am using zsh for my shell. So, any ideas?

Offline

#2 2013-01-07 22:56:19

Lord Bo
Member
Registered: 2012-11-11
Posts: 154

Re: rxvt-unicode and vim cursor shape

I think urxvt is indeed missing this feature. With xterm it works. To test it, you can do

echo -e "\033[4 q"
echo -e "\033[? 25 t"

in your terminal. First shoud set the cursor to an underscore, second toggle the invisibility of the cursor. The first, as I can see, only works in xterm. Look into man 7 urxvt for other valid escape sequences for urxvt.
Edit: You may not be able to set this feature on the fly, but you can invoke urxvt with -uc to get an underlined cursor, but again, that will not help you, if you want to change the cursor in different modes.

Last edited by Lord Bo (2013-01-07 22:57:32)

Offline

#3 2016-04-11 12:54:50

mkingston
Member
Registered: 2013-08-22
Posts: 4

Re: rxvt-unicode and vim cursor shape

I know this is an old topic, but I found it hard to find this info.

Change cursor to a steady bar:
print -n -- "\033[6 q"
Change to a steady block:
print -n -- "\033[2 q"

My emacs hooks to set this in insert mode:

;; Bar cursor
;; These escape sequences work for urxvt
(defun test-send-str-to-terminal (str)
  (unless (display-graphic-p) (send-string-to-terminal str)))
(add-hook 'evil-insert-state-entry-hook (lambda () (test-send-str-to-terminal "\033[6 q")))
(add-hook 'evil-insert-state-exit-hook (lambda () (test-send-str-to-terminal "\033[2 q")))

See man 7 urxvt, search "Set Cursor Style" for more cursors.

Offline

#4 2016-04-11 12:56:59

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 9,183
Website

Re: rxvt-unicode and vim cursor shape

Thanks for sharing, mkingston. I'm going to go ahead and close this ancient thread now.


Sakura:-
Mobo: MSI X299 TOMAHAWK ARCTIC // Processor: Intel Core i7-7820X 3.6GHz // GFX: nVidia GeForce GTX 970 // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 5x 1TB HDD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB