Quantcast

Excel-like "freeze panels" feature in vim

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Excel-like "freeze panels" feature in vim

thomas x

Dear list,

I am currently editing a CSV file with long lines which looks like this:

HeaderA,HeaderB,HeaderC,...,HeaderZ
FieldA1,FieldB1,FieldC1,...,FieldZ1
...
FieldA9,FieldB9,FieldC9,...,FieldZ9

When I am editing a line I always want to see the header line and the
first column. I do not want to use "set wrap". I was wondering if it
is possible to split the window and fake the "freeze panes" feature of
Excel(*), like this:

+-----------------------------------+
|HeaderA,He|derQ,HeaderR,HeaderS,Hea|
|==========+========================| < horizontal
|FieldA4,Fi|ldQ4,FieldR4,FieldS4,Fie|   split
|FieldA5,Fi|ldQ4,FieldR5,FieldS5,Fie|
|FieldA6,Fi|ldQ6,FieldR6,FieldS6,Fie|
+-----------------------------------+
           ^
     vertical split

Let's name the windows AB
                       CD

The issue is: when I am moving the cursor down or up in D, I would
like the window C to be magically scrolled up and down accordingly and
vice-versa. When I am moving the cursor right or left in D, I would
like the window B to be magically scrolled right or left accordingly
and vice-versa.

Is it possible? How can I achieve this?

Thanks
Thomas

(*) The Excel feature: http://www.techonthenet.com/excel/questions/freeze2.php

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Excel-like "freeze panels" feature in vim

Kim Schulz



> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of thomas
> Sent: 9. september 2008 11:12
> To: vim_use
> Subject: Excel-like "freeze panels" feature in vim
>
>
> Dear list,
>
> I am currently editing a CSV file with long lines which looks like this:
>
> HeaderA,HeaderB,HeaderC,...,HeaderZ
> FieldA1,FieldB1,FieldC1,...,FieldZ1
> ...
> FieldA9,FieldB9,FieldC9,...,FieldZ9
>
> When I am editing a line I always want to see the header line and the
> first column. I do not want to use "set wrap". I was wondering if it
> is possible to split the window and fake the "freeze panes" feature of
> Excel(*), like this:
>
> +-----------------------------------+
> |HeaderA,He|derQ,HeaderR,HeaderS,Hea|
> |==========+========================| < horizontal
> |FieldA4,Fi|ldQ4,FieldR4,FieldS4,Fie|   split
> |FieldA5,Fi|ldQ4,FieldR5,FieldS5,Fie|
> |FieldA6,Fi|ldQ6,FieldR6,FieldS6,Fie|
> +-----------------------------------+
>            ^
>      vertical split
>
> Let's name the windows AB
>                        CD
>
> The issue is: when I am moving the cursor down or up in D, I would
> like the window C to be magically scrolled up and down accordingly and
> vice-versa. When I am moving the cursor right or left in D, I would
> like the window B to be magically scrolled right or left accordingly
> and vice-versa.
>
> Is it possible? How can I achieve this?
>


take a look at:
:help scrollbind
:help scrollopt

Should make it possible to do what you need.

kim



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Excel-like "freeze panels" feature in vim

John Beckett-2
In reply to this post by thomas x

thomas wrote:
> I am currently editing a CSV file with long lines which looks
> like this:

Not an answer to your question, but anyone working with CSV files in Vim should try
the following amazing tip:
http://vim.wikia.com/wiki/Working_with_CSV_files

John


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Excel-like "freeze panels" feature in vim

Ivan Tishchenko
In reply to this post by thomas x

such a pity!

Turns out you can't have both leading column and row at the same time... :(
One leading window is easily possible, for example, leading column:

setlocal scrollbind
setlocal scrollopt=hor
above split
1

Ideally, the job would be done by:

  setlocal nowrap scrollbind scrollopt=ver,hor
  vert above split
  below split
  wincmd l
  below split
  wincmd k
  setlocal scrollopt=hor
  wincmd h
  setlocal noscrollbind
  wincmd j
  setlocal scrollopt=ver

But this doesn't work as expected.

The problem is: you cannot set 'scrollopt' locally to a window.  It is
local to a buffer (unlike 'scrollbind' for example).  This is a mistery
to me, why 'scrollopt' is local to a buffer, not window...  Anyway, you
can only tune your windows to scroll either ver, or hor, or in both
directions, and they will all scroll together.  But we want to scroll
upper one only horizontally, and the one on the left -- only vertically,
so...  So we cannot do the job.

Unless we create scratch buffers and play with autocommands to update
them on update of "main" buffer, which will be quite a job...

WBR,
Ivan.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Excel-like "freeze panels" feature in vim

John Beckett-2

Ivan Tishchenko wrote:
> Turns out you can't have both leading column and row at the
> same time...

The CSV tip I mentioned should save the day. It displays the current field name
(from the first row). So the OP could scrollbind a vertical split, showing the first
column on the left, and be content to see only the name of the current field.

John


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Excel-like "freeze panels" feature in vim

thomas x

2008/9/9 John Beckett <[hidden email]>:
>
> Ivan Tishchenko wrote:
>> Turns out you can't have both leading column and row at the
>> same time...
>
> The CSV tip I mentioned should save the day. It displays the current field name
> (from the first row). So the OP could scrollbind a vertical split, showing the first
> column on the left, and be content to see only the name of the current field.

Yes, I will do this. This seems a good compromise to me! Thanks Ivan
for the full explanation and John for the CSV tip. (And, of course,
thanks kim for reminding me the 'scrollbind' option.)

++
Thomas

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Excel-like "freeze panels" feature in vim

Bertram Scharpf
In reply to this post by Ivan Tishchenko

Hi,

Am Dienstag, 09. Sep 2008, 14:34:04 +0400 schrieb Ivan Tishchenko:
>
> such a pity!
>
> Turns out you can't have both leading column and row at the same time... :(
> One leading window is easily possible, for example, leading column:

Not very comfortable, but a combination of these could help, too:

  windo 2,.fold
  windo norm zE

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Excel-like "freeze panels" feature in vim

Tony Mechelynck
In reply to this post by Ivan Tishchenko

On 09/09/08 12:34, Ivan Tishchenko wrote:
> such a pity!
>
> Turns out you can't have both leading column and row at the same time... :(
> One leading window is easily possible, for example, leading column:
[...]

The help says 'scrollopt' is a comma-separated list. Doesn't it work if
you use

        :set sbo=ver,hor

?


Best regards,
Tony.
--
Faith is the quality that enables you to eat blackberry jam on a picnic
without looking to see whether the seeds move.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Excel-like "freeze panels" feature in vim

Ivan Tishchenko


>> such a pity!
>>
>> Turns out you can't have both leading column and row at the same time... :(
>> One leading window is easily possible, for example, leading column:
>>    
> [...]
>
> The help says 'scrollopt' is a comma-separated list. Doesn't it work if
> you use
>
> :set sbo=ver,hor
>
> ?
>  

The problem is: we need four windows:

+---------------+-------------------+
| 1)corner cell | 2)leading line    |
+---------------+-------------------+
| 3)            |       4)          |
| leading       |    the body       |
| column        |                   |
+---------------+-------------------+

All of them display the same buffer, the buffer we edit.

Window 1 must have 'noscrollbind'.
win 2: scrollbind sbo=hor
win 3: scrollbind sbo=ver
win 4: scrollbind sbo=ver,hor

BUT.  But sbo is local to a BUFFER, which means all of them will have
the same value of sbo.

If you use sbo=ver,hor in all of them, windows 2-4 will scroll all
together, and you will not see leading line if you scroll down, or will
not see leading column if you scroll left.

(NOTE that corner cell always stays unmoved, since scrollbind is local
to a WINDOW, not buffer.  Thus, scrolling is off in that window.)

WBR,
Ivan.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Excel-like "freeze panels" feature in vim

Tony Mechelynck

On 09/09/08 16:39, Ivan Tishchenko wrote:

>
>>> such a pity!
>>>
>>> Turns out you can't have both leading column and row at the same time... :(
>>> One leading window is easily possible, for example, leading column:
>>>
>> [...]
>>
>> The help says 'scrollopt' is a comma-separated list. Doesn't it work if
>> you use
>>
>> :set sbo=ver,hor
>>
>> ?
>>
>
> The problem is: we need four windows:
>
> +---------------+-------------------+
> | 1)corner cell | 2)leading line    |
> +---------------+-------------------+
> | 3)            |       4)          |
> | leading       |    the body       |
> | column        |                   |
> +---------------+-------------------+
>
> All of them display the same buffer, the buffer we edit.
>
> Window 1 must have 'noscrollbind'.
> win 2: scrollbind sbo=hor
> win 3: scrollbind sbo=ver
> win 4: scrollbind sbo=ver,hor
>
> BUT.  But sbo is local to a BUFFER, which means all of them will have
> the same value of sbo.
>
> If you use sbo=ver,hor in all of them, windows 2-4 will scroll all
> together, and you will not see leading line if you scroll down, or will
> not see leading column if you scroll left.
>
> (NOTE that corner cell always stays unmoved, since scrollbind is local
> to a WINDOW, not buffer.  Thus, scrolling is off in that window.)
>
> WBR,
> Ivan.

'scrollopt' is global (not window-local and not buffer-local); it's
'scrollbind' which is window-local. Hm. You might be able to hack
something with a CursorMoved,CursorMovedI autocommand (to force the two
windows at left to display the far left column and the two top ones to
display their top line) but I'm not sure.

Best regards,
Tony.
--
I think we can all agree that there is not enough common courtesy shown
... HEY!  PAY ATTENTION WHEN I'M TALKING TO YOU DAMMIT!  I said I think
we can all agree that there is not enough common courtesy shown today.
When we take the time to be courteous to each other, we find that we
are happier and less likely to engage in nuclear war.  This point was
driven home by the recent summit talks, where Nancy Reagan and Raisa
Gorbachev, each of whose husband thinks the other's husband is vermin,
were able to sit down at a high-level tea and engage in courteous
conversation ...
                -- Dave Barry, "The Stuff of Etiquette"

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Excel-like "freeze panels" feature in vim

Ivan Tishchenko



> 'scrollopt' is global (not window-local and not buffer-local); it's
> 'scrollbind' which is window-local. Hm. You might be able to hack
> something with a CursorMoved,CursorMovedI autocommand (to force the two
> windows at left to display the far left column and the two top ones to
> display their top line) but I'm not sure.
>
> Best regards,
> Tony.
>  

Well, yes.  I thought about it.  It's just that having 'scrollopt' local
to a window would do the job with those 10 commands I posted, and with
autocommands I'll have to define them, and most probably will have to
define additional functions, and, again, autocommands are local to a
BUFFER, not a window (and I've not seen any tips on how to make them
local to a window, so I'll have to save additional info in
window-variables, thank God they exist), and I've got to make cleanup of
autocommands and vars when those windows are closed, etc...  Quite a
job, too.

WBR,
Ivan.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Excel-like "freeze panels" feature in vim

Jürgen Krämer-4
In reply to this post by Ivan Tishchenko


Hi,

Ivan Tishchenko wrote:

>
>
> The problem is: we need four windows:
>
> +---------------+-------------------+
> | 1)corner cell | 2)leading line    |
> +---------------+-------------------+
> | 3)            |       4)          |
> | leading       |    the body       |
> | column        |                   |
> +---------------+-------------------+
>
> All of them display the same buffer, the buffer we edit.
>
> Window 1 must have 'noscrollbind'.
> win 2: scrollbind sbo=hor
> win 3: scrollbind sbo=ver
> win 4: scrollbind sbo=ver,hor
>
> BUT.  But sbo is local to a BUFFER, which means all of them will have
> the same value of sbo.
>
> If you use sbo=ver,hor in all of them, windows 2-4 will scroll all
> together, and you will not see leading line if you scroll down, or will
> not see leading column if you scroll left.
>
> (NOTE that corner cell always stays unmoved, since scrollbind is local
> to a WINDOW, not buffer.  Thus, scrolling is off in that window.)

if you don't need to edit in windows 1 to 3 you might be able to
initialize them with new buffers and

  :.read your-csv-file

into them. Additionally you might want to remove superfluous (empty)
lines and set the buftype to nofile so you don't get bothered with
unmodified buffers on exit.

Regards,
Jürgen

--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Excel-like "freeze panels" feature in vim

Ivan Tishchenko


> if you don't need to edit in windows 1 to 3 you might be able to
> initialize them with new buffers and
>
>   :.read your-csv-file
>
> into them. Additionally you might want to remove superfluous (empty)
> lines and set the buftype to nofile so you don't get bothered with
> unmodified buffers on exit.
>  

Sure!  It's just that those windows won't get updated if I modify
original buffer (e.g. add new line, and it won't show in "leading
column" window).

WBR,
Ivan.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Loading...