1

I have a blinking block cursor in the XTerm. The goal is to always be able to tell my current position. It usually works fine, but it fails when I place my cursor on a background similar to the cursor color - a prime example for what I mean are searches in Vim: they have yellow background, my cursor is white (due to .foreground in .Xesources), and because of this I can hardly tell which of the highlighted results is the current one.

I'd like to have my cursor invert the current character color, so that I can still have yellow search results (but the character pointed by the cursor will have dark background and light text when the cursor blinks). The solution should work at least for this specific scenario.

I'm not sure if this is something that should be done in Vim, or in XTerm's configuration. I tried to search for this on the web and in the manpages, but failed to find anything relevant.

Note that I don't use gvim, I use console Vim. Many resources mention guibg=reverse for Vim, but this won't work here.

  • The console version of guibg is ctermbg. Does setting it help? – muru May 9 '15 at 11:09
  • Unfortunately, ctermbg doesn't seem to have reverse option - .vimrc highlights it as bad, and it doesn't seem to do anything. – rr- May 9 '15 at 11:09
  • What about :hi Search cterm=reverse? – muru May 9 '15 at 11:16
  • While Vim no longer seems to complain about validity of this setting, it doesn't seem to do anything as well: the character under cursor has white background and yellow font, and the rest of the search has yellow background and black font. It looks like the cursor color is hardcoded in XTerm. This happens also when I clean my configuration with xrdb -load /dev/null... the background is always the same as the cursor's. – rr- May 9 '15 at 11:22
0

I can think of several ways, besides changing the colors, to make the cursor easier to find. One could toggle the cursorcolumn or the cursorline on and off or set them permanently on. With my favorite colorschemes, this can either be not enough of a hint or it can be too ugly to bear.

Another solution is to toggle search highlighting – off with :se nohls and on with :sehls. These are persistent settings, and one can forget to return to highlighted search.

To turn off highlighting for the current search, I mapped 'Ctrl+l' (that's an ell, not a one) with the following setting in my .vimrc. Highlighting will return with the next search. 'Ctrl+l' is convenient for this remapping because its default mapping is to the :redraw command to refresh the screen.

nnoremap <silent> <C-l> :<C-u>nohlsearch<CR><C-l>

I also have a mapping, using 'F3', to toggle persistent search highlighting:

nnoremap <F3> :set hlsearch! hlsearch?<CR>
0

If you do not specify the cursor color, xterm will draw the cursor using the reverse of the foreground/background colors on the cell where the cursor happens to be. That's for xterm. Other programs do not behave that way.

This is what the xterm manual says:

cursorColor (class CursorColor)
Specifies the color to use for the text cursor. The default is "XtDefaultForeground". By default, xterm attempts to keep this color from being the same as the background color, since it draws the cursor by filling the background of a text cell. The same restriction applies to control sequences which may change this color.

Setting this resource overrides most of xterm's adjustments to cursor color. It will still use reverse-video to disallow some cases, such as a black cursor on a black background.

At the same time, if you select text, e.g., using the mouse, then xterm attempts to make both the cursor and the selection look different. There are resource settings related to this, depending on your preferences: highlightReverse, highlightSelection and highlightTextColor.

Xterm's scheme for reversing foreground/background colors assumes that the cursor is on a cell which is already readable. If your text is yellow, and the background white, the cursor will be no more readable than the text.

Xterm does also have an escape sequence which could be used to set the cursor color, but vim does not provide a way to use this to override the cursor color (actually, doing this would probably be complicated).

Since xterm's default scheme for coloring the cursor does not detract from readability, the way to fix this in vim is to choose a color theme which is readable (no yellow-on-white).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.