23

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?

  • @stephane Any way to go more 10% from current line ? Doesn't see anything referenced to navigate in this in the help :h N% – mtk Feb 19 '14 at 12:02
  • I've just tried a relative percentage +50% It doesn't work, so no. I've updated my answer to show help information. – X Tian Feb 19 '14 at 12:16
41

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}
  • 2
    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 '18 at 14:50
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.