Tip #263: color active line
tip karma |
Rating 15/11, Viewed by 1400
|
created: |
|
June 18, 2002 7:05 |
|
complexity: |
|
basic |
author: |
|
Armin Rehm ([email protected]) |
|
as of Vim: |
|
6.0 |
This tip shows how to color the active line, the line in which the cursor is, for better reading.
You should try possibility 2 before 1, IMHO it is mostly usable.
possibility 1:
:au! CursorHold * let @/ = '\%' . line('.') . 'l.*'
:set ut=500
explanation:
After 500 ms of waiting for you to hit a key, vim sets the search register to a pattern that matches the current line.
problem:
Register / holds the search pattern, so you cannot have color the active line and search.
Therefore another solution:
possibility 2:
:highlight CurrentLine guibg=darkgrey guifg=white (or whatever colors you want)
:au! Cursorhold * exe 'match CurrentLine /\%' . line('.') . 'l.*/'
:set ut=100
explanation:
This solution uses 'match' to highlight a string, it does not interface with the current search pattern.
addition:
Turning the highlighning off:
:au! Cursorhold
:match none
The order of these commands are important. If :match none is executed first, the autocommand would
almost immediately execute another match command.
references to vim help:
:help Cursorhold
:help 'ut'
:help /\%l
:help "/
:help \%
<<Bored of ur arrow shapped mouseptr? |
F5 Compile and Run, F8 Compile (ala Visual Studio) >>
Additional Notes
|