ajp
ajp

Reputation: 2463

set cursor to middle line on vim startup

I would like to sometimes invoke vim with a startup command (by passing -c "something" on the command line) that centers the cursor in the middle of the screen - the same effect as if I pressed M immediately after opening vim. However the -c option only accepts ex commands, which M is not. Is this possible (and how if so)?

For background, in combination with scrolloff = 999, this would allow me to begin scrolling forward with j immediately upon opening vim.

Upvotes: 0

Views: 266

Answers (2)

FDinoff
FDinoff

Reputation: 31429

You can use normal mode commands with the normal (or norm) ex command

vim -c 'norm M' <filename>

Take a look at :h :normal

Upvotes: 5

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

-c "let &scrolloff=999-&scrolloff"

should do the trick.

Upvotes: 0

Related Questions