Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I open a file with gvim with the following command line option,

gvim file +5

I would like the current line (the 5th line) be scrolled to the center of gVIM's window, Is that possible?

|                            |
|                            |
|                            |
|                            |
|  this line was selected    |
|                            |

By default, it wasn't centered

share|improve this question
Are you referring to the same behavior that typing zz in normal mode would offer? – Bernhard Oct 22 '12 at 15:28
@Bernhard zz is not an editor command? – warl0ck Oct 22 '12 at 15:42
@Bernhard anyway, if this "zz" can be used once, it would solve my problem – warl0ck Oct 22 '12 at 15:43
up vote 3 down vote accepted

You can use

gvim file +5 -c "normal zz"

The -c option allows you to specify an editor command to run when starting vim. zz, as others have mentioned, centers the screen on the cursor line.

share|improve this answer

Use an autocommand.

au VimEnter * normal zz
share|improve this answer
And if he does not want to do this by default? – Bernhard Oct 22 '12 at 15:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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