Your Linux Data Center Experts

When I'm coding, and sometimes when I'm writing, I like to see a lot of code. Usually I just maximize my window vertically, which gives me around 51 lines, and to the side of it I have a couple of windows I can use for a Python shell, regular shell, or another editing session. Sometimes I just want to see more code… Read on for a nifty trick I found in vim.

I had an idea that I might like to run with a vim window in full screen mode, split into two long windows side by side. I did a quick help search in vim and found the “scrollbind” option, which causes multiple windows to scroll together. This is how the “vimdiff” scrolling works.

So, you can have two windows side-by-side with one page continuing onto the next, like with a book.

To try it out, open up vim on /etc/services (for example), preferably with your window as big as you can make it, then do the following:

  • 1G – Move to the first line of the file if you aren't already there.
  • Control-W v – Create two windows, split vertically.
  • :set scrollbind – Set the current window to have scrollbind enabled.
  • Control-W l – Move to the window to the right.
  • Control-F – Scroll forward a page.
  • :set scrollbind – Set the current window to have scrollbind enabled.
  • Control-W h – Move to the window to the left.

Now, you can scroll in the window to on the left (or the right window even), and the other window moves with it.

If I reduce the size of my window font a little bit, I can even get 3 side-by-side and do my editing in the middle window, with additional page before and after on either side. With this smaller font, I get 75 lines in each window, 3 across. That's a lot of context.

Not sure if I'll find it useful, but it's worth trying.

comments powered by Disqus

Join our other satisfied clients. Contact us today.