URxvt: vim and cursorColor [invisible cursor or invisible cursor text]

2

1

Introduction

I've always used a light-background terminal and a dark-background editor (vim). On this I'm not willing to compromise. In any case, I've just switched from xterm to urxvt ($TERM == rxvt-unicode-256color) mainly to due an unresolved fontconfig/xft font truncation bug in xterm, and urxvt's ability to reflow text properly (there are other perks though, so please don't blindly suggest switching terminals). Unfortunately I have one problem with urxvt that I can't solve: the cursor color in vim is invisible. Let me explain with each terminal's default behaviour:

XTerm:

  • cursor color defaults to the foreground color of the underlying text, and therefore varies. If there is no underlying text, it defaults to the foreground color (white or black, usually)
  • text color under cursor is pulled to the background color (black or white, usually)
  • XTerm ignores a cursorColor setting of "#000000" and instead uses default behaviour

Therefore, text under the cursor is only invisible in XTerm when the cursor color matches (as near as possible) the background color.

URxvt:

  • cursor color defaults to black.
  • text color under cursor is pulled to white.

Therefore, text under the cursor is only invisible in URxvt when the cursor color is white

Back to the problem:

The URxvt cursor is invisible in vim because I use a dark colorscheme (black cursor on black background). I can't change the cursor to color to white in ~/.Xdefaults because I use a light-background terminal, this would lead to a white cursor in a white background over white text: both invisible cursor and invisible font. However, while vim normally doesn't support changing the cursor color, with a little bit of hackery in ~/.vimrc it becomes possible. Unfortunately, a white or lighter-colored cursor leads to either invisible text or at least much less legible text.

Overview

Invisible Cursor:

  • explanation: black cursor on black background.
  • solution: change cursor color to white (or a lighter color)
  • problem: leads to invisible text (or harder to read text)

Invisible Text:

  • explanation: white cursor over white text
  • solution: ????

Solutions

I'm hoping either that URxvt can support XTerm's cursorColor/cursorTextColor behaviour, or at least support modifying the color of the text under the cursor, though of course I'm open to other solutions.

user19087

Posted 2014-03-10T21:24:12.767

Reputation: 513

Did you try setting the cursor color to "reverse"? – romainl – 2014-03-10T21:59:23.743

I'm not sure what you mean. -xrm "*cursorColor: reverse" -> urxvt: unable to parse color 'reverse', using pink instead. – user19087 – 2014-03-10T22:24:58.073

Well, the urxvt-specific resource is cursorColor2, with such a nondescript name no wonder I didn't originally find it. Unfortunately it seems incompatible with the vim hack because I have yet to find a corresponding escape sequence. – user19087 – 2014-03-10T22:51:56.833

And the reset sequence in the vim hack doesn't actually work with urxvt. – user19087 – 2014-03-10T22:52:26.867

Yes, urxvt doesn't seem to care at all about vim's cterm=reverse. That's unfortunate. – romainl – 2014-03-10T23:20:23.663

Most likely cterm is unsupported by XTerm, rather vim sends an escape sequence to the terminal, and in this particular instance reverse is unsupported by URxvt. Do you know which escape sequence or resource vim's reverse sets? Perhaps I'll add support to URxvt. I'm also considering adding support for XTerm's dynamic color reset OSC sequences and extended them to URxvt's cursorColor2 as well (relatively easy; the problem is no one responds). – user19087 – 2014-03-11T04:53:48.650

No answers