Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always display the first few lines of a buffer in Vim

Tags:

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.

like image 737
keflavich Avatar asked Nov 12 '11 00:11

keflavich


People also ask

How do I go down multiple lines in vim?

This will simply do Ctrl + e 10 times. You can change the number to the number of lines you want it to scroll at once. It's important to note that the mapping is of the noremap type. Otherwise VIm will enter an infinite loop once you press the combination.

How do I select the number of lines in vim?

If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor. Finally, you can select text in columns by pressing ctrl+v and moving up or down the block.

What is a buffer in vim?

Buffers in vim are the in-memory text of files. Your window is a viewport on a buffer. You can switch between open buffers, this is similar to tabs in other editors. Vim does have a concept of tabs too, but they are slightly different, read more about tabs in the Windows section.


2 Answers

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 _.

like image 193
Karoly Horvath Avatar answered Nov 09 '22 00:11

Karoly Horvath


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.

like image 26
Idan Arye Avatar answered Nov 09 '22 00:11

Idan Arye