LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-08-2016, 11:50 PM   #1
andrew.comly
Member
 
Registered: Dec 2012
Distribution: Trisquel-Mini 7.0, Lubuntu 14.04, Debian lxde 8.0
Posts: 308
Blog Entries: 2

Rep: Reputation: 16
Question VIM: Can't change cursor color


VIM: Invisible Cursor
cursor background colors

I am on Lubuntu 14.04 using VIM - Vi IMproved 7.4 through xterm.

I would like to see my cursor in both "morning" and "shiny" color themes. Unfortunately by default both the background and foreground color are the same as the background, thus making it impossible to see where the cursor is.

The following attempts are solutions I found online.

_____________________________________________
Attempt 01: http://alvinalexander.com/linux/vi-v...-scheme-syntax
I tried the 4 examples below:
Code:
highlight Comment ctermbg=DarkGray
highlight Constant ctermbg=Blue
highlight Normal ctermbg=Black
highlight Special ctermbg=DarkMagenta
The above commands successfully change the color for "comment, constant, Normal and Special" groups. However, the following just aren't the same:
Code:
highlight NonText ctermbg=Black
highlight Cursor ctermbg=Green
Both of the above two commands have no effect!

I try other background and foreground colors, but nothing works.

_____________________________________________
Attempt 02: http://andrewradev.com/2011/08/06/ma...custom-colors/

I made sure the following was already in my /usr/share/vim/vim74/colors/am.vim colorscheme file:
Code:
set background=dark

hi clear
if exists("syntax_on")
syntax reset
endif

:let g:colors_am = 'colorscheme_am'
Now when I execute :colors Cursor ctermbg=Black I get:
Code:
E185: Cannot find color scheme 'cursor ctermbg=Black'
E185: Cannot find color scheme 'Cursor ctermbg=Black'
So Andrew Radev's tutorial didn't work for me either.

_____________________________________________
Attempt 03: https://unix.stackexchange.com/quest...ursor-in-vimrc Evan Teitelman

The only main answer talks about pasting commands in your ~/.Xdefaults or .Xresources file. I found an .Xresources in my ~ directory. But there is only the following line of content:
Code:
xterm*font: *-fixed-*-*-*-18-*
What part of this file should I paste this? Pasting it naturally to the end (2nd line) for the contents:
Code:
xterm*font: *-fixed-*-*-*-18-*
XTerm*cursorColor: #000000
URxvt.cursorColor: Black
I then saved, reopened vim, and I still can't see my cursor.

_____________________________________________
Attempt 04 https://unix.stackexchange.com/quest...ursor-in-vimrc Stephane Chazelas
Luckily, one of my favorites Stephane Chazelas had posted a solution, which I then typed into vim command mode, but the command
Code:
:printf '\033]12;#f50\7'
produces the following error message:
Code:
E492: Not an editor command: printf '\033]12;#f50\7'
I even tried pasting it into .Xresources:
Code:
xterm*font: *-fixed-*-*-*-18-*
printf '\033]12;#f50\7'
{fail}
_____________________________________________
Attempt 05: http://vim.wikia.com/wiki/Configuring_the_cursor
I try pasting the following into my colorscheme (am.vim) file:
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
Presto! I can now see my cursor(Normal: Red; Insert: Orange). But how to change to another color?

I am currently learning unix shellscripting, and even though the
Code:
echo -ne "\033]12;red\007"
looks really familiar from some earlier Prompt 1-4 tutorial I read before (as a reference):
Code:
Black Background	bash	prompt	ANSI COLOR CODES	bakblk='\e[40m'
Black Bold	bash	prompt	ANSI COLOR CODES	bldblk='\e[1;30m'
Black Regular	bash	prompt	ANSI COLOR CODES	txtblk='\e[0;30m'
Black Underline	bash	prompt	ANSI COLOR CODES	unkblk='\e[4;30m'
hicolor	bash	prompt	ANSI COLOR CODES	HC="\[\033[1m\]"
inverse background and foreground	bash	prompt	ANSI COLOR CODES	INV="\[\033[7m\]"   
reboot	bash	prompt	ANSI COLOR CODES	UL="\[\033[4m\]"
Red Background	bash	prompt	ANSI COLOR CODES	bakred='\e[41m'
Red Bold	bash	prompt	ANSI COLOR CODES	bldred='\e[1;31m'
Red Regular	bash	prompt	ANSI COLOR CODES	txtred='\e[0;31m'
Red Underline	bash	prompt	ANSI COLOR CODES	undred='\e[4;31m'
reset	bash	prompt	ANSI COLOR CODES	RS="\[\033[0m\]"
Text Reset 	bash	prompt	ANSI COLOR CODES	txtrst='\e[0m'
However, the rest is quite incomprehensible, thus I don't know how to change from "Red" for Normal mode and Orange for Insert mode to other colors for Normal/Insert modes.

Does anyone know how to change the cursor and NonText colors? My preferred colors for cursor background is black and for foreground is white?

Last edited by andrew.comly; 11-09-2016 at 01:29 AM. Reason: clarity
 
Old 11-09-2016, 06:14 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,476
Blog Entries: 11

Rep: Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441
Quote:
Originally Posted by andrew.comly View Post
VIM: Invisible Cursor
cursor background colors

I am on Lubuntu 14.04 using VIM - Vi IMproved 7.4 through xterm.

I would like to see my cursor in both "morning" and "shiny" color themes. Unfortunately by default both the background and foreground color are the same as the background, thus making it impossible to see where the cursor is.

The following attempts are solutions I found online.
...
_______________________
Attempt 05: http://vim.wikia.com/wiki/Configuring_the_cursor
I try pasting the following into my colorscheme (am.vim) file:
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
Presto! I can now see my cursor(Normal: Red; Insert: Orange). But how to change to another color?

...
However, the rest is quite incomprehensible, thus I don't know how to change from "Red" for Normal mode and Orange for Insert mode to other colors for Normal/Insert modes.

Does anyone know how to change the cursor and NonText colors? My preferred colors for cursor background is black and for foreground is white?
You can change the colors in this example by simply changing the color names, like this, where I have hilighted changes in red...

Code:
if &term =~ "xterm\\|rxvt"
" use an orange cursor in insert mode
let &t_SI = "\<Esc>]12;white\x7"
" use a red cursor otherwise
let &t_EI = "\<Esc>]12;blue\x7"
silent !echo -ne "\033]12;blue\007"
" reset cursor when vim exits
autocmd VimLeave * silent !echo -ne "\033]112\007"
" use \003]12;gray\007 for gnome-terminal
endif
The &t_EI is set on end insert mode, so you would probably want that to be the same as the initial startup color. I have set both to blue just to set them apart. If you always want a white cursor then simply set all of these to white.

These are termcap control strings. You can find more info in man termcap and man terminfo of course, and a complete list of those recognized by Vim, along with a few defined only for Vim using the termcap format here.

I hope this helps!
 
1 members found this post helpful.
Old 11-11-2016, 07:54 AM   #3
andrew.comly
Member
 
Registered: Dec 2012
Distribution: Trisquel-Mini 7.0, Lubuntu 14.04, Debian lxde 8.0
Posts: 308

Original Poster
Blog Entries: 2

Rep: Reputation: 16
Smile

Astrogeek,
On the termcap link webpage there is info on how to change the cursor color, thanks for sharing your source.

Just wondering, would anyone know how to change the NonText color? Still nothing on NonText color on that page.

But that's not of vital importance, which is now because of your explanation I finally have a visible cursor, and I can continue making progress.

Thanks a lot!

Last edited by andrew.comly; 11-11-2016 at 07:57 AM.
 
Old 11-11-2016, 11:24 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,476
Blog Entries: 11

Rep: Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441Reputation: 3441
From the same set of docs I first linked (always a good place to start!), start here and search down page for NonText.

I also found this older post here on LQ which provides a working Vim config with a nontext color definition.

Although I am a full-time Vim user, I do not recall ever setting that in my own Vim configs, so no personal experience. Please let me know if either of those helps.
 
1 members found this post helpful.
Old 11-12-2016, 05:57 AM   #5
andrew.comly
Member
 
Registered: Dec 2012
Distribution: Trisquel-Mini 7.0, Lubuntu 14.04, Debian lxde 8.0
Posts: 308

Original Poster
Blog Entries: 2

Rep: Reputation: 16
Talking "nontext" group question migrated

Astrogeek,
Thanks again for solving my main problem: cursor fg and bg color!

Remaining problem concerning possible "NonText" group migrated to a separate question here.
 
  


Reply

Tags
ide, terminal, vim, xterm


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to change the cursor color on the console? thomas2004ch Linux - Software 2 01-12-2015 04:50 AM
[SOLVED] How to change vi/vim color setting casualzone Linux - Newbie 8 07-20-2011 12:58 AM
Vim Cursor Color Mr_Munkey Linux - Software 0 01-06-2006 05:42 PM
How to Change the Cursor Color in Ncurses mac57 Programming 0 04-02-2005 03:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration