By pressing gg
and G
you can jump to both ends of a buffer.
42G
jumps to the line 42.
Is there any quick g
shortcut to jump to the middle of buffer. Something like roughly round(number of lines/2)G
?
You can use N%
to jump to the Nth percent of the file. So e.g. 50%
jumps roughly to the middle of the buffer. See the help at :h N%
I use these mappings in my own settings:
nnoremap <expr> M (line('$')/2).'G'
xnoremap <expr> M (line('$')/2).'G'
onoremap <expr> M (line('$')/2).'G'
It's pretty simple, it simply evaluates the expression (line('$')/2).'G'
before running the mapping. line('$')
is the number of the last line in the buffer, which we divide by two. Then the .'G'
just appends 'G' to the resulting string.
If you like using the default M
(Middle of visible screen), you could make this a leader mapping so that you don't overwrite it. For example:
nnoremap <expr> <leader>m (line('$')/2).'G'
xnoremap <expr> <leader>m (line('$')/2).'G'
onoremap <expr> <leader>m (line('$')/2).'G'
You can use N%
to jump to the Nth percent of the file. So e.g. 50%
jumps roughly to the middle of the buffer.
See the help at :h N%