keflavich
keflavich

Reputation: 19215

Always display the first few lines of a buffer in Vim

I often use gVim and Vim to view data tables in which the top row is the header. Is there any way to display this top row while browsing through the rest of the table? Ditto columns for the case in which the first column is a row heading.

EDIT: I accepted a good answer (and there were others) for showing the top column.

The horizontal (first row) equivalent to the answer I accepted is

:vert split
ctrl+w 5 |

or

ctrl+w v
ctrl+w 10 |

It would be nice to be able to do both, but apparently that is not straightforward.

Upvotes: 7

Views: 3765

Answers (4)

ib.
ib.

Reputation: 28954

In this case it is convenient to use the preview window (see :help preview-window). To open the preview window showing the first, say, eight lines of the current file, issue the following commands.

:set previewheight=8
:pedit +1

Use the :pclose command (:pc, for short) or the Ctrl+WZ shortcut to close the preview window.

Upvotes: 2

Idan Arye
Idan Arye

Reputation: 12603

If you're working with datatables alot, you might want to take a look at the csv plugin. it has the :HeaderToggle command that does exactly what you want, and many more commands that you might find useful.

Upvotes: 5

ruakh
ruakh

Reputation: 183321

See http://vim.1045645.n5.nabble.com/Excel-like-quot-freeze-panels-quot-feature-in-vim-td1178008.html for some good ways to show leading rows or leading columns (though not easily both at once, unfortunately).

Upvotes: 1

Karoly Horvath
Karoly Horvath

Reputation: 96266

You could open the file in two windows (command line: vim -o file file, or ctrl+w n :o file) and then one is fixed and you can scroll in the other window.

If you want to see the first 5 rows press ctrl+w 5 _.

Upvotes: 8

Related Questions