How may I tweak the Vim <C-F> command to show only 1 line from the prior screenful?

Well I tried to map a normal mode command that scrolls forward by 1 line less than the number of lines in the window, and multiply that by the prefix arg if given.

With no prefix arg this works properly:

:no <expr> <C-F> (v:count1*(winheight(0)-1))."\<C-E>"

But with a prefix arg it appears to both evaluate the expression and then also prefix the prefix arg to the result, so if the window shows 11 lines it scrolls from line 1 to:

prefix scrolls to
 ----   --------
 none       11
   1       111
   2       221
   9       991
  10     10101

With or without a prefix arg this at least shows the proper number of lines to scroll, so that seems like progress:

:no <C-F> :<C-u>echo (v:count1*(winheight(0)-1))<cr>

But, with or without a prefix arg, this doesn't work, it moves the cursor in inconsistent ways and doesn't scroll:

:no <C-F> :<C-u>normal (v:count1*(winheight(0)-1))."\<c-e>"<cr>

I'm stumped. How would you do it?

  • :help 'lines' is the total number of lines in the whole "screen" taken by Vim, including the command-line, the tab-line (if any), the status-line (if any), the tool-bar (if any), and, eventually, other windows than the current one. This makes it a very poor fit for what you are trying to do. Even if you NEVER EVER use those features, you will at least need to factor in :help 'cmdheight'. :help winheight() would be a better starting point.
    – romainl
    Commented May 10 at 7:01
  • Thank you i rewrote the question accordingly.
    – gregrwm
    Commented May 13 at 16:07

1 Answer 1


I would do:

:nnoremap <c-f> <c-f><c-y>

It works fine with count or without count.

Or to continue where you started:

:nnoremap <C-f> <cmd>execute 'normal' (v:count1*(winheight(0)-1)) . "\<c-e>"<cr>

Remark: the first versiin:

:no <expr> <C-F> (v:count1*(winheight(0)-1))."\<C-E>"

Doesn't work because the original count is still there. If winheight is 11

  • with 1 you have 1. 1 * 10 or `110
  • with 2 you have 2 . 2 * 10 or 220

Remark: in your second version I suspect Vim to not interpret the argument of the normal command as an expression but as pure literal list of characters entered by the user.

  • Your first one shows 3 prior lines. This shows just one: :no <c-f> <c-f><c-e> But a prefix arg doesn't repeat the entire mapping. Your second one looks like a winner, Thanks!
    – gregrwm
    Commented May 11 at 0:39
  • Your second one works from the : prompt, but when defined in the VIMINIT environment variable, invoking complains E117: Unknown function: normal. What's up with that?
    – gregrwm
    Commented May 11 at 2:58
  • Thanks for the feedback :-) It is odd. It should be the same behavior. Did you type it the same way? In particular do you have a space between 'normal' and (v:count1*(winheight(0)-1)) . "\<c-e>"<cr>? Commented May 11 at 3:48
  • 1
    it was a quoting issue, fixed it, it works, thanks again.
    – gregrwm
    Commented May 13 at 15:25
  • Thanks for the feedback! I'm glad you solved your problem :-) Commented May 13 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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