You are here

Vim: Scrolling a file with no line-breaks

Submitted by Druss on Sat, 2010-08-14 23:56

When a file has no line-breaks and is just one single line, navigating line by line is obviously not an option. Some editors wrap the text and treat each pseudo-line as a separate element and allow us to scroll through them. Others don't. Vim, by default doesn't.

Or to be more precise, Vim (and GVim) do not allow us to scroll through such files using the arrow keys. Instead, the following short-cuts do the business:

Scroll up: g, k / g, up
Scroll down: g, j / g, down
Beginning of the line: g, ^ [i.e. g, SHIFT + 6 on a keyboard with a US layout]
End of the line: g, $ [i.e. g, SHIFT + 4]

... and so on. More information on these short-cuts can be found at VimDoc.

While we can see that it is certainly possible to scroll these pseudo-lines as we wish, let's add a little bit of convenience by remapping these short-cuts to the standard UP and DOWN keys. To do so, type:

:noremap <up> gk<code>
<code>:noremap <down> gj<code>

To make this remapping permanent, the above two lines will need to be added to your <code>.vimrc
file.

I hope that this helps somebody out there :)

JH