Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[vim] Show where the 80th column is

24 views
Skip to first unread message

Patrick Doyle

unread,
Dec 6, 2001, 3:00:17 PM12/6/01
to
I hope this is not a FAQ, but I couldn't find it...

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

Al Sharka

unread,
Dec 6, 2001, 4:10:23 PM12/6/01
to
Patrick Doyle wrote:
>
> 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?

:se ruler

Will display cursor position in the lower right(ish) corner of the
screen.

Patrick Doyle

unread,
Dec 6, 2001, 9:37:42 PM12/6/01
to

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. :-)

Jürgen Krämer

unread,
Dec 7, 2001, 2:45:51 AM12/7/01
to

Hi,

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

Balazs Szalai

unread,
Dec 7, 2001, 3:56:59 AM12/7/01
to
> :syntax match OverEighty /\%>80c.*/
> :highlight OverEighty guibg=gray
> :syntax on
wow, great! I think he think of...
:syntax match OverEighty /\%80c./

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

Peppe

unread,
Dec 7, 2001, 8:12:55 AM12/7/01
to
Thus wrote Balazs Szalai <balazs...@eei.ericsson.se>

> > :syntax match OverEighty /\%>80c.*/
> > :highlight OverEighty guibg=gray
> > :syntax on
> wow, great! I think he think of...
> :syntax match OverEighty /\%80c./

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

Patrick Doyle

unread,
Dec 7, 2001, 10:35:22 AM12/7/01
to
=?iso-8859-1?Q?J=FCrgen=20Kr=E4mer?= <jkra...@habel.de> wrote:

>
>Patrick Doyle wrote:
>>
>> 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.)

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

Patrick Doyle

unread,
Dec 7, 2001, 10:56:18 AM12/7/01
to
Patrick Doyle <doy...@eecg.toronto.edu> wrote:

>jkra...@habel.de wrote:
>>
>>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
>
>Wow, that's perfect. Thanks!

Oh oh, I take it back. It doesn't seem to work with existing syntax
highlighting. Oh well.

Charles E. Campbell

unread,
Dec 7, 2001, 2:46:13 PM12/7/01
to
In article <GnzD...@ecf.utoronto.ca>,
---------------------------------------------------------------------

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

Walter Briscoe

unread,
Dec 7, 2001, 10:52:55 AM12/7/01
to
In article <slrna11g2j....@newton.gbar.dtu.dk> of Fri, 7 Dec
2001 13:12:55 in comp.editors, Peppe <c92...@student.dtu.dk> writes

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

Balazs Szalai

unread,
Dec 10, 2001, 5:09:24 AM12/10/01
to Charles E. Campbell
See Peppe's mail. Using "match" instead of "syn match" works fine
regardless the syntax.
B

Markus Fischer

unread,
Dec 10, 2001, 7:16:26 AM12/10/01
to
In article <3C1489D4...@eei.ericsson.se>, Balazs Szalai wrote:
> See Peppe's mail. Using "match" instead of "syn match" works fine
> regardless the syntax.

>Holy shit< , its incredibly what vim offers :-)

--
Remove 'nospam-' from my sender domain to contact me privately.

Peppe

unread,
Dec 10, 2001, 10:02:10 AM12/10/01
to
Thus wrote Walter Briscoe <wbri...@ponle.demon.co.uk>

> 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

Patrick Doyle

unread,
Dec 11, 2001, 10:49:34 AM12/11/01
to
In article <slrna11g2j....@newton.gbar.dtu.dk>,

Peppe <c92...@student.dtu.dk> wrote:
>
>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.

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?

Peppe

unread,
Dec 12, 2001, 3:14:45 AM12/12/01
to
Thus wrote Patrick Doyle <doy...@eecg.toronto.edu>

> 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

Patrick Doyle

unread,
Dec 13, 2001, 10:21:01 AM12/13/01
to
In article <slrna1e4fk....@newton.gbar.dtu.dk>,

Peppe <c92...@student.dtu.dk> wrote:
>Thus wrote Patrick Doyle <doy...@eecg.toronto.edu>
>
>> 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.

Ah, ok. Thanks for your help!

0 new messages