Change colour of cursor and matching bracket

209 views
Skip to first unread message

Dotan Cohen

unread,
Sep 30, 2012, 5:12:14 AM9/30/12
to vim use
Where in the fine manual is it mentioned how to change the colour of
the cursor and the colour of the matching parenthesis / bracket for
all file types? I have tried ":h cursor color" and several other
phrases, the only relevant one that I found it "h color" which did not
lead me to the answer. I have tried "highlight MatchParen cterm=bold
ctermfg=red ctermbg=blue" but this did not change the colour of the
matching parenthesis or bracket.

It seems that no matter what I define in .vimrc, VIM still uses the
reverse colours of the item (swap background and foreground) for the
cursor, and a cyan background for the matching parenthesis / bracket.

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com

Marcin Szamotulski

unread,
Sep 30, 2012, 6:31:19 AM9/30/12
to vim...@googlegroups.com
In vim (running in uxterm terminal) I use the following command to
change the color of the cursor:

:!echo -ne "\033]12;midnightblue\007"<CR>

I have several maps to different colors, setup like this:

map @1 :!echo -ne "\033]12;midnightblue\007"<CR><CR>

but there is the Cursor highlight group (:help hl-Cursor) which can be
used (here it doesn't work in vim, but it works in gvim).

To change the matching parent you have to play with MatchParen (:help
hl-MatchParen and also :help pi_paren.txt).

For example to get black on white matching paren (in both vim and gvim)
you can use:

hi MatchParen ctermfg=black ctermbg=white guifg=black guifg=white

Best regards,
Marcin Szamotulski


Erik Christiansen

unread,
Sep 30, 2012, 7:29:45 AM9/30/12
to vim use
On 30.09.12 11:12, Dotan Cohen wrote:
> Where in the fine manual is it mentioned how to change the colour of
> the cursor and the colour of the matching parenthesis / bracket for
> all file types? I have tried ":h cursor color" and several other
> phrases, the only relevant one that I found it "h color" which did not
> lead me to the answer. I have tried "highlight MatchParen cterm=bold
> ctermfg=red ctermbg=blue" but this did not change the colour of the
> matching parenthesis or bracket.

For the cursor, I just set the initial colour in the xterm:

col='-fg yellow -bg darkslategrey -cr red' # Colours
/usr/bin/xterm $col # and lots more options.

In Vim, I then only change the cursor colour to indicate whether we're
in insert mode or not, without having to look down at the status bar:

" Cursor Appearance: (Insert_Mode == Green, Normal_Mode == Red)
if &term =~ "xterm"
let &t_SI = "\<Esc>]12;green\x7"
let &t_EI = "\<Esc>]12;red\x7"
endif

But the method could be used in other contexts, I guess.

As regards MatchParen colouring, I've only made sure that is turned
off, since it drove me nuts when I tried it. The bouncing cursor is more
than enough.

Erik

--
Habit is habit, and not to be flung out of the window by any man, but
coaxed down-stairs a step at a time.
- Mark Twain, "Pudd'nhead Wilson's Calendar

Bram Moolenaar

unread,
Sep 30, 2012, 9:30:05 AM9/30/12
to Erik Christiansen, vim use

Erik Christiansen wrote:

> On 30.09.12 11:12, Dotan Cohen wrote:
> > Where in the fine manual is it mentioned how to change the colour of
> > the cursor and the colour of the matching parenthesis / bracket for
> > all file types? I have tried ":h cursor color" and several other
> > phrases, the only relevant one that I found it "h color" which did not
> > lead me to the answer. I have tried "highlight MatchParen cterm=bold
> > ctermfg=red ctermbg=blue" but this did not change the colour of the
> > matching parenthesis or bracket.
>
> For the cursor, I just set the initial colour in the xterm:
>
> col='-fg yellow -bg darkslategrey -cr red' # Colours
> /usr/bin/xterm $col # and lots more options.
>
> In Vim, I then only change the cursor colour to indicate whether we're
> in insert mode or not, without having to look down at the status bar:
>
> " Cursor Appearance: (Insert_Mode == Green, Normal_Mode == Red)
> if &term =~ "xterm"
> let &t_SI = "\<Esc>]12;green\x7"
> let &t_EI = "\<Esc>]12;red\x7"
> endif
>
> But the method could be used in other contexts, I guess.
>
> As regards MatchParen colouring, I've only made sure that is turned
> off, since it drove me nuts when I tried it. The bouncing cursor is more
> than enough.

I also use a different cursor color for Insert mode. It's nice, but
recently it has started to cause terminal window flicker. I asked
Thomas Dickey and he blames Ubuntu Compiz. I'm running Ubuntu 12.04 and
an automatic update about a month ago started the problem. It first
happened after a reboot, one of the updates before that must have caused
it.

Still don't know how to fix it. It gets a bit annoying. Searching for
Ubuntu screen flicker has many hits, but I haven't spotted the right one
yet.

--
VOICE OVER: As the horrendous Black Beast lunged forward, escape for Arthur
and his knights seemed hopeless, when, suddenly ... the animator
suffered a fatal heart attack.
ANIMATOR: Aaaaagh!
VOICE OVER: The cartoon peril was no more ... The Quest for Holy Grail could
continue.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Erik Christiansen

unread,
Sep 30, 2012, 10:23:15 AM9/30/12
to vim use
On 30.09.12 15:30, Bram Moolenaar wrote:
> I also use a different cursor color for Insert mode. It's nice, but
> recently it has started to cause terminal window flicker. I asked
> Thomas Dickey and he blames Ubuntu Compiz. I'm running Ubuntu 12.04 and
> an automatic update about a month ago started the problem. It first
> happened after a reboot, one of the updates before that must have caused
> it.

On a new install of Ubuntu, two things seem invaluable; turning off
NetworkManager before doing anything else, and ensuring that automatic
upgrades are disabled. Stability is more conducive to sanity and
productivity than having the latest bugs, ISTM. (OK, an occasional
peek at the Update Manager, and acceptance of security upgrades, could
let in a new bug too, but I've been fortunate so far.)

Incidentally, to protect against unfortunate upgrades, I keep the older
OS version, installing the new version in another partition. If it isn't
much chop, it can be overwritten when a better one comes along. If it's
OK, then installs alternate between partitions, clobbering the older
version, as I upgrade once every 3 years or so.

> Still don't know how to fix it. It gets a bit annoying. Searching for
> Ubuntu screen flicker has many hits, but I haven't spotted the right one
> yet.

Giving up Compiz for Metacity or other WM, temporarily, might confirm
that Compiz is the culprit. Then reversion to an older version ought to
fix it, with a bit of luck. (An "apt-get remove --purge compiz"
hopefully won't leave much of the current install, but e.g. with apache2
I've had to clean out leftover subordinate packages.)

Erik

--
A man is like a rusty wheel on a rusty cart,
He sings his song as he rattles along and then he falls apart.
- Richard Thompson

Dominique Pellé

unread,
Sep 30, 2012, 10:35:06 AM9/30/12
to vim...@googlegroups.com
I also use different colors for the cursor in insert mode
vs normal mode with xubuntu-12.04 (with all updates)
and I have not noticed any flicker. Perhaps you can
try whether installing xfce solves your flicker issue:

1/ sudo apt-get update
2/ sudo apt-get install xubuntu-desktop
3/ Log out.
4/ Select xfce to login

I remember having very slow refresh and flicker
in vim a long time ago, and solved it at the time
by installing the latest Nvidia driver.

-- Dominique

Ben Fritz

unread,
Sep 30, 2012, 5:20:40 PM9/30/12
to vim...@googlegroups.com
On Sunday, September 30, 2012 4:12:21 AM UTC-5, dotancohen wrote:
> Where in the fine manual is it mentioned how to change the colour of
>
> the cursor and the colour of the matching parenthesis / bracket for
>
> all file types?

:he hl-Cursor
:he hl-MatchParen

> I have tried ":h cursor color" and several other
>
> phrases, the only relevant one that I found it "h color" which did not
>
> lead me to the answer. I have tried "highlight MatchParen cterm=bold
>
> ctermfg=red ctermbg=blue" but this did not change the colour of the
>
> matching parenthesis or bracket.
>

This should have worked, assuming you're using Vim in a terminal and not gvim. For gvim you'd need guifg and guibg highlights. See :help :highlight, :help highlight-args, and the following text for details on the command.



>
> It seems that no matter what I define in .vimrc, VIM still uses the
>
> reverse colours of the item (swap background and foreground) for the
>
> cursor

You don't mention specifically what you tried, but the default cursor highlight (at least for my gvim install on Lubuntu) is guibg=fg guifg=bg, which would indeed reverse the color, so this makes sense if nothing you tried actually was correct. So what DID you try, if you can't get it working with a "hi Cursor ..." command?

> and a cyan background for the matching parenthesis / bracket.
>

You used ctermfg and ctermbg, so I'll assume you're using a terminal (and a color one at that). Do the numbers (instead of the names) in :help cterm-colors work any better?

What does :verbose hi Cursor and :verbose hi MatchParen show you? Perhaps the :hi command in your .vimrc is being overwritten later by a colorscheme command or something.

Do :hi commands for other items work? Do you get colorful and customizable syntax highlighting, for example? Perhaps your terminal is misconfigured so that Vim doesn't realize it's a color terminal. I won't be much help in that regard, but I know you can cheat within Vim by setting t_Co and some other terminal codes. Do a :helpgrep t_Co and browse the list of hits for details. Or search the wiki: http://vim.wikia.com/wiki/index.php?search=t_Co&fulltext=Search

Bram Moolenaar

unread,
Sep 30, 2012, 5:53:57 PM9/30/12
to Dominique Pellé, vim...@googlegroups.com
I'm using ATI/AMD. I tried installing their proprietery driver.
Resulted in my desktop being 640 x 480 :-( Then running the
display manager to change the resulution has the OK button off-screen.
AAAaaaargggg! Managed to hit it by pressing Tab the right number of
times.

Well, the flicker is less, it's just so short now that it is hardly
noticeable. But the flicker is still there.

--
Sorry, no fortune today.

Marcin Szamotulski

unread,
Oct 1, 2012, 12:54:32 AM10/1/12
to vim...@googlegroups.com
The flickering seems to be not just Ubuntu problem. I am running Gentoo
and can observe it here. As a terminal I use uxterm (version 279).

Best regards,
Marcin

Bram Moolenaar

unread,
Oct 1, 2012, 5:05:02 PM10/1/12
to Marcin Szamotulski, vim...@googlegroups.com
Could it be a problem with Gnome desktop? I should try out xfce.

I deinstalled the ATI driver again. It was causing display errors for
images in Chrome. I suspect it also caused my focus-follows-mouse
setting to be lost. Seems like a bad driver.

--
BRIDGEKEEPER: What is your favorite colour?
GAWAIN: Blue ... No yelloooooww!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

François Ingelrest

unread,
Oct 2, 2012, 2:11:44 AM10/2/12
to vim...@googlegroups.com
On Sun, Sep 30, 2012 at 11:53 PM, Bram Moolenaar wrote:
> I'm using ATI/AMD. I tried installing their proprietery driver.
> Resulted in my desktop being 640 x 480 :-( Then running the
> display manager to change the resulution has the OK button off-screen.
> AAAaaaargggg! Managed to hit it by pressing Tab the right number of
> times.

When the window goes out of the screen, you can generally hold the ALT
key to drag the window by clicking anywhere on it. This way you can
move the bottom buttons back on screen.

Dotan Cohen

unread,
Oct 2, 2012, 7:11:37 AM10/2/12
to vim...@googlegroups.com
On Sun, Sep 30, 2012 at 11:20 PM, Ben Fritz <fritzo...@gmail.com> wrote:
> On Sunday, September 30, 2012 4:12:21 AM UTC-5, dotancohen wrote:
>> Where in the fine manual is it mentioned how to change the colour of
>>
>> the cursor and the colour of the matching parenthesis / bracket for
>>
>> all file types?
>
> :he hl-Cursor
> :he hl-MatchParen
>

Thank you, but that just leads to a link to Syntax highlighting.
Ostensibly this is what I want, but on my system (Kubuntu with VIM 7.3
running in Konsole, and also tried SSHing into CentOS with VIM 7.2
from the same Konsole) configuration such as the following do not
change the matched parenthesis:

highlight MatchParen cterm=bold ctermfg=red ctermbg=blue


>> I have tried ":h cursor color" and several other
>>
>> phrases, the only relevant one that I found it "h color" which did not
>>
>> lead me to the answer. I have tried "highlight MatchParen cterm=bold
>>
>> ctermfg=red ctermbg=blue" but this did not change the colour of the
>>
>> matching parenthesis or bracket.
>>
>
> This should have worked, assuming you're using Vim in a terminal and not gvim. For gvim you'd need guifg and guibg highlights. See :help :highlight, :help highlight-args, and the following text for details on the command.
>

Yes, this was in VIM, not GVIM.


>> It seems that no matter what I define in .vimrc, VIM still uses the
>>
>> reverse colours of the item (swap background and foreground) for the
>>
>> cursor
>
> You don't mention specifically what you tried, but the default cursor highlight (at least for my gvim install on Lubuntu) is guibg=fg guifg=bg, which would indeed reverse the color, so this makes sense if nothing you tried actually was correct. So what DID you try, if you can't get it working with a "hi Cursor ..." command?
>
>> and a cyan background for the matching parenthesis / bracket.
>>
>
> You used ctermfg and ctermbg, so I'll assume you're using a terminal (and a color one at that). Do the numbers (instead of the names) in :help cterm-colors work any better?
>

No, unfortunately the numbers did not work either. I'll start playing
around with clean .vimrc and .vim/ to see if something in there is
interfering.


> What does :verbose hi Cursor and :verbose hi MatchParen show you? Perhaps the :hi command in your .vimrc is being overwritten later by a colorscheme command or something.
>
> Do :hi commands for other items work? Do you get colorful and customizable syntax highlighting, for example?

Yes, syntax highlighting works in all languages that I have tried.


> Perhaps your terminal is misconfigured so that Vim doesn't realize it's a color terminal. I won't be much help in that regard, but I know you can cheat within Vim by setting t_Co and some other terminal codes. Do a :helpgrep t_Co and browse the list of hits for details. Or search the wiki: http://vim.wikia.com/wiki/index.php?search=t_Co&fulltext=Search

Thanks, I'll get on that!
Reply all
Reply to author
Forward
0 new messages