When writing code in Vim, I'd prefer to keep it under 80 columns, but
sometimes there are longer lines. I don't want to use anything
like :set columns=80 because I'd like to avoid wrapping long lines if
my screen is wide enough to display them.
What I'd like is some kind of visual reminder of where the 80th column
is. Perhaps a vertical line, or the cursor changing shape past the
80th column, or the text being printed in a different colour. I don't
know, the vim guys probably have better ideas than I do anyway.
Does Vim have anything like this?
As a corollorary, how does one find such information generally? The
Vim help files are nice when I already know the name of the command or
variable, but otherwise, how can I find this kind of thing without
bothering all you nice people?
Thanks.
--
--
Patrick Doyle
doy...@eecg.toronto.edu
:se ruler
Will display cursor position in the lower right(ish) corner of the
screen.
Ok, thanks. I have that one already, so if that's the best Vim has
to offer, then I guess that will have to do. :-)
Patrick Doyle wrote:
>
> When writing code in Vim, I'd prefer to keep it under 80 columns, but
> sometimes there are longer lines. I don't want to use anything
> like :set columns=80 because I'd like to avoid wrapping long lines if
> my screen is wide enough to display them.
>
> What I'd like is some kind of visual reminder of where the 80th column
> is. Perhaps a vertical line, or the cursor changing shape past the
> 80th column, or the text being printed in a different colour. I don't
> know, the vim guys probably have better ideas than I do anyway.
>
does the following do what you want? I am not sure how it interacts
with already existing syntax highlighting.
:syntax match OverEighty /\%>80c.*/
:highlight OverEighty guibg=gray
:syntax on
It gives every character beyond the 80th column a gray background. (If
you want it to highlight everything beyond a specific _virtual_ column,
use /\%>80v.*/ instead.)
Regards,
Jürgen
--
Jürgen Krämer Softwareentwicklung/-support
Habel GmbH mailto:soft...@habel.de
Hinteres Öschle 2 Tel: (0 74 61) 93 53 15
78604 Rietheim-Weilheim Fax: (0 74 61) 93 53 99
is enough, although there's some conflicts. Is there a way to add a rule in addition to any?
Btw in
> :syntax match OverEighty /\%>80c.*/
^ ^
the two characters has the same sideeffect, so onyl one fo them is enough. However I'm
a bit confused with the first, I haven't seen such in the docs (is the greater than 80?)
B
Strict reading would probably agree; personally I would highlight the
remainder of the line to make it stand out even further.
Anyway, although syntax highlighting can be nice, I would not like to
add a group everywhere as you could break carefully crafted
dependencies between groups.
For this kind of simple highlighting, I use eg.
:match Error /\%>80v./
Note the "v" instead of "c" - it works on virtual columns and thus
deals better with tabs.
> is enough, although there's some conflicts. Is there a way to add a rule in addition to any?
Probably a "containedin=ALL" addition.
> Btw in
> > :syntax match OverEighty /\%>80c.*/
> ^ ^
> the two characters has the same sideeffect, so onyl one fo them is enough. However I'm
> a bit confused with the first, I haven't seen such in the docs (is the greater than 80?)
Have a look at ":help /\%c".
Peppe [who really likes the new regexps in vim 6]
--
"Before you criticize someone, walk
Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
c92...@student.dtu.dk (o o) he gets angry, he'll be a mile away
----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
Wow, that's perfect. Thanks!
It seems to work fine. I'm not sure what this means:
"WARNING: When inserting or deleting text Vim does not automatically
update the matches. This means Syntax highlighting quickly becomes
wrong."
http://www.vim.org/html/pattern.html#/\%c
Oh oh, I take it back. It doesn't seem to work with existing syntax
highlighting. Oh well.
True -- the syntax highlighting is attempting to apply regexp patterns
to recognize syntax and to apply highlighting when it recognizes
something. The "OverEighty" idea will interfere, even when
containedin=ALL is used, because it will prevent proper recognition
of syntax. Having "contains=ALL" would allow groups (frequently
xyzError groups) to be recognized that ought not to be.
Unfortunately, one cannot seem to place "sign"s on a specific
text area via some regexp (see :he sign; configure --enable-workshop).
Regards,
C Campbell
--
Charles E Campbell, Jr, PhD _ __ __
Goddard Space Flight Center / /_/\_\_/ /
c...@NgrOyphSon.gPsfAc.nMasa.gov /_/ \/_//_/
PGP public key: http://www.erols.com/astronaut/pgp.html
This partially explained my lack of understanding of the RE.
I take it that /\%>80v./ is roughly equivalent to "In virtual columns of
more than 80, match any character". I infer this matches more than once
on the basis of the count criterion. /\%80v.*/ has a similar effect and
presumably means "At column 80, match all characters". I don't
understand why /\%80v/ matches column 80 and /\*>80v/ matches column 81
and the last column but not those in between. I am delighted that
somebody has written some syntax commands which are almost within my
understanding!
--
Walter Briscoe
>Holy shit< , its incredibly what vim offers :-)
--
Remove 'nospam-' from my sender domain to contact me privately.
> I take it that /\%>80v./ is roughly equivalent to "In virtual columns of
> more than 80, match any character". I infer this matches more than once
> on the basis of the count criterion. /\%80v.*/ has a similar effect and
> presumably means "At column 80, match all characters".
Just about.
\%>80v. A character past the 80th virtual column.
All such characters will match individually.
\%80v. The character in virtual column 80.
\%80v.* Any number of characters starting in virtual column 80.
Matches as one group.
Also matches end of line after virtual column 79 (no
no characters -- a zero length match).
> I don't
> understand why /\%80v/ matches column 80 and /\*>80v/ matches column 81
> and the last column but not those in between.
Actually, all the positions match but with zero width. Verify this
with
:match NONE
:se hls
/\%>80v
nnnnn
Any of those n's should find positions after the 80th virtual column
(and the end of line after an 80th virtual column).
It is a special case, though, as you do not ask for eg. a character.
Peppe
This is great. Thanks! I now use this:
:hi Eightieth ctermbg=blue
:match Eightieth /\%80v/
It's exactly what I was looking for.
The help files don't make it clear: what's the difference between
:match and :syntax match?
> The help files don't make it clear: what's the difference between
> :match and :syntax match?
:match is sort of a poor man's :syntax where you can only match one
pattern (that could be complex) with a single group. If you define a
new :match the old will be overwritten.
The good thing is that it works independently of syntax highlighting
so you can do stuff like matching in a special column without having
to concider a lot of :syntax oddities.
Peppe
Ah, ok. Thanks for your help!