Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

2 Answers 2

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
2  
And if he does not want to do this by default? –  Bernhard Oct 22 '12 at 15:40

Your Answer

 
discard

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.