Vim - zt will redraw the window with the cursor at the top. Can you redraw with it say, 4 lines down?
Asked Answered
A

3

5

Reading the manual with ':help z' shows a variety of commands which can redraw the window, e.g. z.to redraw with the cursor in the centre or zb to redraw with it at the bottom of the screen.

zt is nice but I would find it much more comfortable to be able to redraw with the cursor 25% of the way down the page (so that what I was just writing is still visible). Is there an easier way to accomplish this other than macro-ing it?

Antefix answered 13/11, 2014 at 17:56 Comment(1)
Not sure whether this is what you're looking for, but you can use set scrolloff=n (where n is some number of lines) to keep a specified number of lines always visible above the cursor at the top and bottom of the screen.Libelant
M
8

You can use the 'scrolloff' option:

set scrolloff=4

See :help 'scrolloff'.

Mondragon answered 13/11, 2014 at 18:12 Comment(0)
C
1

Here's the mapping (assigned to <Leader>zt) I use to put a number of lines above the cursor line at the top of the window:

nnoremap <silent> <Leader>zt :<C-u>exec 'normal! ' . v:count . 'kzt' . v:count . 'j'<CR>

If you don't supply a prefix, it will put the line above the cursor at the top of the window.

Corry answered 13/11, 2014 at 22:14 Comment(1)
You can consider using <C-y> in the mapping, too.Scour
S
0

Regarding @echristopherson 's answer, this mapping should work, too:

nnoremap zt zt3<C-y>

and for the default behaviour:

nnoremap zT zt " 3<C-y> is not applied because of the n`nore` map.
Scour answered 15/11, 2014 at 2:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.