Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving to middle of huge file in Vim or gVim

Tags:

vim

shortcut

Is there a Vim command to move to the middle of a huge file without calculating (total lines/2) and using j? Something like zz, zt, or zb, which moves only around the current screen?

like image 501
Raghav Avatar asked Feb 01 '16 23:02

Raghav


People also ask

How do I switch between files in Vim?

Using windows. Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l ) to navigate through open windows. Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one. Starting vim with a -o or -O flag opens each file in its own split.

How do you jump between lines in Vim?

If we are in the vim editor, then simply do this, “Press the ENTER key, write the Line number, and press Shift+ g”: Again the output is the same.


1 Answers

You can use one of the features that vim borrowed from elvis: it accepts a percentage of the file directly. For example, typing

50%

jumps to the middle of the file.

In vim, if you enter

:h up-down-motions

that leads to the section describing the feature:

{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}
like image 127
Thomas Dickey Avatar answered Oct 05 '22 23:10

Thomas Dickey