Discussion:
Column ruler (like line numbers) in vi / vim / gvim
(too old to reply)
Polytropon
2014-09-05 23:23:27 UTC
Permalink
There is _one_ feature that I didn't find in vi / vim / gvim,
and especially in regards of column-oriented data files, this
would be really helpful: a real COLUMN RULER on top. I have
"set number" and "set ruler" already in ~/.vimrc, but this
involves too much "eye travel". I'd like to quickly see column
numbers (on top) like I can see line numbers (on the left).

As a grown-old mainframe person, I'm thinking about something
like this:

|...+....1....+....2....+....3....+....4....+....5....+....6

Something that you would recognize from ISPF/PDF.

It could also look like this, like in SEU:

....+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6

Or even this:

1 2 3 4 5 6
----+----0----+----0----+----0----+----0----+----0----+----0

The ruler should be located in the first line on top of the file,
but not be part of the file.

Is there a way to add this to gvim? Ideally it should accomodate
to the "set nowrap" or "set wrap" setting (lines longer than the
window width are either wrapped or scrolled horizontally). It
should be shown on top of the current view (no matter how far you
are into the file vertically). It should work similarly to the
line numbers displayed on the left.

Is it possible to achieve this without re-programming (g)vi(m)
from scratch? :-)
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
Alex Stangl
2014-09-06 02:26:58 UTC
Permalink
Post by Polytropon
As a grown-old mainframe person, I'm thinking about something
|...+....1....+....2....+....3....+....4....+....5....+....6
1 2 3 4 5 6
----+----0----+----0----+----0----+----0----+----0----+----0
The ruler should be located in the first line on top of the file,
but not be part of the file.
Hi Polytropen,

Check out
http://vim.1045645.n5.nabble.com/Horizontal-Ruler-in-interface-td5590000.html

I just tried the last suggestion on that page (from Christian Brabrandt)
and it works great, and can be easily adapted to any of the formats you
like. To make the ruler go away, you can type Ctrl-W o

It's not clear how you want the ruler to work in wrap mode,
so maybe that doesn't work as you like.

Regards,

Alex
Polytropon
2014-09-06 04:43:49 UTC
Permalink
Post by Alex Stangl
Hi Polytropen,
Check out
http://vim.1045645.n5.nabble.com/Horizontal-Ruler-in-interface-td5590000.html
I just tried the last suggestion on that page (from Christian Brabrandt)
and it works great, and can be easily adapted to any of the formats you
like. To make the ruler go away, you can type Ctrl-W o
I had already found this, but it didn't work as intended.
I found it in my local ~/.vim/plugin/ directory (deactivated).

But it was an inspiration, so I came up with this idea which
is 99% of what I was searching for:

setl scrollbind scrollopt+=hor
abo sp +enew
call setline(1,' ....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+....|')
let &l:stl="%#Normal#".repeat(' ',winwidth(0))
res 1
setl scrollbind nomod buftype=nofile winfixheight nonumber nocursorline
wincmd p

First I had the original

call setline(1,repeat('....+....|',20))

line (modified from 2nd to 1st line of the buffer) and then had
a replacement orgy

:1s/|/1/1
:1s/|/2/2
:1s/|/3/3
:1s/|/4/4
:1s/|/5/5
:1s/|/6/6
:1s/|/7/7
:1s/|/8/8
:1s/|/9/9

to replace the 1st | with 1, the 2nd with 2 and so on (up to 9).
But then I thought: I can do this manually, it would be easier. :-)

Maybe there's an expression for "search for the pattern P, and
replace P with the number n, where n corresponds to the n-th
instance of the pattern found". Maybe a regex wizard can tell
me if this is possible?

The spaces infront of the manually defined ruler represent the
indentation for line numbers (which the buffer should not have).
The spacing is for up to 999 lines, this is what vim aligns the
numbers to (as in "%3d").

As you can see, the buffer also has an override for "set cursorline"
which I have in my ~/.vimrc.

Cosmetically I haven't found a way yet to remove the empty line
between the buffer and the file to edit. Currently it looks
like this (vim /usr/include/stdio.h):

....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+.

1 /*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
Post by Alex Stangl
It's not clear how you want the ruler to work in wrap mode,
so maybe that doesn't work as you like.
I didn't want the ruler in wrap mode - it wouldn't work. :-)
Instead I had to "set nowrap" for any content edited which
works nicely with the above solution: when scrolling the
file horizontally, the buffers scrolls along.



There is still one problem:

The "wincmd p" doesn't seem to be executed, I have to manually
use Ctrl+W p to be able to work with a file (instead with the
ruler).

Oh, and an additional quit command is to be used for the ruler
(:q :q or :qa!), except I use the window manager's key combination
to close the window (possible with gvim, but for vim inside a
terminal, the whole terminal is closed).
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
Paul Kraus
2014-09-06 17:41:37 UTC
Permalink
Post by Polytropon
There is _one_ feature that I didn't find in vi / vim / gvim,
and especially in regards of column-oriented data files, this
would be really helpful: a real COLUMN RULER on top. I have
"set number" and "set ruler" already in ~/.vimrc, but this
involves too much "eye travel". I'd like to quickly see column
numbers (on top) like I can see line numbers (on the left).
As a grown-old mainframe person, I'm thinking about something
|...+....1....+....2....+....3....+....4....+....5....+….6
I have been cheating this for years, I use a line very much like the above as a comment and separator when I am writing scripts :-)

#————1————2————3————4————5————6————7————8

--
Paul Kraus
***@kraus-haus.org

Loading...