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

Sorry for a short answer, but

just type 50%

{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}
| improve this answer | |
  • 4
    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

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

| improve this answer | |

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.