简体   繁体   中英

How to center the editor window back on the cursor in VSCode?

I'm using VSCode as my text editor. I'm curious, is there a keybinding for centering the editor window on the cursor, when the window is a lot of lines below/above it such that it's not visible on the screen? I've tried looking at the default keybindings by going to FIle > Preferences > Keyboard Shortcuts , but I see no such options for centering the window.

There is no such keybinding / command built-in.

I couldn't stand that either, so I created a VSCode extension. You can find it and install it here on the marketplace . The default shortcut is CTRL + L .

如果您使用的是 vscodevim,则zz应该可以工作。

As @kwood put it, there is an extension Center Editor Window in the marketplace that meets this end.

I would like to make an answer here, to complement that -- even the extension's author did not explicitly state in the marketplace page -- if you would like to change the default key binding ( Ctrl + L ), you may try put the following lines in the keybindings.json for the keyboard bindings.

{
    "key": "cmd+k cmd+c",
    "command": "center-editor-window.center",
    "when": "editorTextFocus"
},

The above command sets ⌘ Command + K , ⌘ Command + C as the keyboard shortcut.


Apart from that, you may set

"center-editor-window.threeStateToggle": true,

in the settings.json for VS Code settings so that it will switch among three states (center, top, bottom) instead of one (center).

如果您想始终将光标保持在中心,您可以将设置Cursor Surrounding Lines更改为一个非常高的数字(100 是可以的),这样就可以了。

There is also a keybinding at

Tools > Options > Environment > Keyboard > edit.ScrollLineCenter

I don't know if this was implemented when you asked the question or when the other answer was submitted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM