41

I often open large files, looking through logs for finding info. As all lines have timestamp in my case and I am sure of in which part of the whole file the info is present which I am interested in. For example,

  • in the bottom half of the file contents(50% or beyond) or
  • about 10% more towards the end of file or
  • scroll down more 20% of original file.

So, to navigate quickly in this fashion i.e. with percentage-wise - Is there any existing functionality already available in vim?

0

2 Answers 2

71

Sorry for a short answer, but

just type 50%

                                                        *N%*
{count}%                Go to {count} percentage in the file, on the first
                        non-blank in the line |linewise|.  To compute the new 
                        line number this formula is used:
                            ({count} * number-of-lines + 99) / 100
                        See also 'startofline' option.  {not in Vi}
1
  • 7
    This answer is flawless. And it could become even more so if you could make a relative motion as well: that is, moving for example 10% forward, regardless of looking where you're at. Also note that you should not enter : to access command mode.
    – nilon
    Mar 25, 2018 at 14:50
4

There's the [count]% command (how intuitive!) for absolute navigation. For relative navigation, you have to calculate the amount yourself. E.g. to scroll down 33%:

:exe 'normal!' 33 * line('$') / 100 . 'j'

(You probably want to create mappings that use v:count for these.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .