How may I scroll with vim into a big file?

2019-03-09 08:15发布

问题:

I have a big file with thousands of lines of thousands of characters.

I move the cursor to 3000th character.

If I use PageDown or Ctrl+D, the file will scroll but the cursor will come back to the first no-space character.

There's is an option to set to keep the cursor in the same column after a such scroll ?

I have the behavior with gvim on Window, vim on OpenVMS and Cygwin.

回答1:

CTRL-E - scroll down
CTRL-Y - scroll up

100<CTRL-E> will scroll down 100 lines for example

If you like using PageUp, PageDown or Ctrl+D etc. you can set the "nostartofline" option

:set nostartofline


回答2:

Well, one easy way to do so is using the movement keys. For example, to go down 100 lines keeping the cursor at the same column: "100j"

Edit:

Alright, searching a little more to really find an answer to your question, there's an option to do exactly what you want:

:set nostartofline


回答3:

A Recent Plugin

I am using terryma/vim-smooth-scrolling plugin as it provides a very nice and smooth scrolling.


To install, you can use Vundle:

Bundle terryma/vim-smooth-scrolling

As stated in the doc, you can set up 3 arguments: distance, duration and speed.

I am using this in my .vimrc file:

noremap <silent> <c-b> :call smooth_scroll#up(&scroll*2, 10, 4)<CR>
noremap <silent> <c-f> :call smooth_scroll#down(&scroll*2, 10, 4)<CR>


回答4:

This might not suit your situation at all, but if it makes it easier to break the lines up you can break them at a certain character e.g. after ':'

:%s/:/\r&/g

Or every 80 characters

:%s/.\{80}/&\r/g