如何在 Sublime Text 中保持当前行在屏幕上垂直居中?

How to keep current line centered vertically on the screen in Sublime Text?

我想让当前选中的行保持在屏幕的垂直中心。

在 VIM 中,这是通过 :set scrolloff=9999 命令实现的。

在 Sublime Text 中是否有任何选项或插件可以做到这一点?

import sublime_plugin
class AlwaysCenterCommand(sublime_plugin.EventListener):
    def on_modified(self, view):
        sel = view.sel()
        pt = sel[0].begin() if len(sel) == 1 else None
        if pt != None:
            view.show_at_center(pt)

不多选修改时居中。就是这样。

或者您也可以只使用该区域。

import sublime_plugin
class AlwaysCenterCommand(sublime_plugin.EventListener):
    def on_modified(self, view):
        sel = view.sel()
        region = sel[0] if len(sel) == 1 else None
        if region != None:
            view.show_at_center(region)

https://forum.sublimetext.com/t/always-centered-cursor/4005


另一种选择

Buffer Scroll is a simple Sublime Text plug-in which remembers and restores the scroll, cursor positions, also the selections, marks, bookmarks, foldings, selected syntax and optionally the colour scheme, when you open a file. Will also remember different data depending the position of the file in the application (example file1 in window1 has scroll line 30, file1 in window2 has scroll in line 40)

Also, via preferences, allows to enable syncing of scroll, bookmarks, marks and folds between cloned views, live.

Syncing features are disabled by default. You need to enable these via the preferences. Main menu -> Preferences -> Package Settings -> BufferScroll -> Settings Default. You may want to copy and paste your edited preferences to "Settings Users" located under the same sub-menu. To keep your preferences between updates.

Requested by Kensai this package now provides "typewriter scrolling": The line you work with is automatically the vertical center of the screen.

https://github.com/titoBouzout/BufferScroll