Center Vertically
Center Vertically automatically adds top padding to short files so their contents sit closer to the middle of the editor viewport instead of hugging the top edge of a large screen.
Why This Exists
VS Code has an editor.padding.top setting, but it is static. This extension recalculates that padding as you move between files, resize the window, or edit the active document.
Important Limitation
VS Code does not currently expose a per-editor or per-window top padding API. The extension works by updating the normal editor.padding.top setting.
To reduce weird behavior across multiple VS Code windows, the extension writes padding to workspace settings by default. That means separate workspace windows should not fight over the same global User setting. Two windows opened on the same workspace can still affect each other because they share the same workspace settings.
For files opened without a workspace, the extension falls back to User settings because there is no workspace setting target available.
Settings
centerVertically.enabled: turns automatic centering on or off.
centerVertically.viewportHeightLines: fallback visible line count for short files. Lower this if the padding is too large.
centerVertically.centerRatio: where short-file content sits in the empty vertical space. 0 keeps it at the top, 0.5 centers it.
centerVertically.paddingConfigurationTarget: where editor.padding.top is written. Use workspace to reduce cross-window conflicts, or global for one shared User setting.
Commands
Center Vertically: Recenter Current File
Center Vertically: Toggle Auto-Center
Local Install
Package the extension:
npx --yes --package node@20 --package @vscode/vsce -- vsce package --allow-missing-repository
Install the VSIX:
code --install-extension center-vertically-0.0.1.vsix
Publishing Notes
Before publishing publicly, add:
- a
publisher in package.json matching your Marketplace publisher ID
- a repository URL
- a license file
Then publish with vsce publish using Node 20 or newer.