Sublime Text 2:如何在不移动光标的情况下向上/向下翻页

问题描述 投票:14回答:3

我在OS X 10.8.4上使用ST2。当我使用Home和End键时,视口移动并且光标保持不变。这是标准的Mac行为,也是我所期待的。

但是,当我使用Page Up(pageup / pgup)和Page Down(pagedown / pgdn)时,光标会随着视口移动。这不是其他Mac应用程序的行为,我希望光标也可以单独保留这些键。

通过将其添加到我的键绑定中,我已经能够完成这一半工作:

[
   { "keys": ["pageup"], "command": "scroll_lines", "args" : {"amount": 30.0} },
   { "keys": ["pagedown"], "command": "scroll_lines", "args" : {"amount": -30.0} }
]

但是,金额是硬编码的。看起来viewport_extent会让我获得视口的高度,但是如何在键绑定文件中使用它呢?这甚至是正确的解决方案吗?我觉得要获得这种行为是一项非常艰巨的工作。

提前致谢。

cursor sublimetext3 sublimetext2
3个回答
16
投票

只需使用Fn+up进行翻页,然后使用Fn+down进行翻页。


7
投票

要做到这一点,需要一个文本插件。感谢ST论坛上的用户bizoo,您不必自己编写:

http://www.sublimetext.com/forum/viewtopic.php?f=3&t=12793

这完全符合我的预期。


Sublime Text 3更新:你可以按照下面的说明进行操作,文件应该以.py(例如scroll_lines_fixed.py)结尾进行微小更改,并且应该在~/Library/Application Support/Sublime Text 3/Packages/User/文件夹中松散。


Sublime Text 2更新:这个不太清楚,并且还使用了一个可以想象将来会死的裸URL。所以这里有一个更完整的解释,你需要做什么。

  1. 将这四行添加到Sublime Text 2> Preferences> Key Bindings - User,在文件中已有的任何方括号内: [ { "keys": ["ctrl+up"], "command": "scroll_lines_fixed", "args": {"amount": 1.0 } }, { "keys": ["ctrl+down"], "command": "scroll_lines_fixed", "args": {"amount": -1.0 } }, { "keys": ["pageup"], "command": "scroll_lines_fixed", "args" : {"by": "pages", "amount": 1.0 } }, { "keys": ["pagedown"], "command": "scroll_lines_fixed", "args" : {"by": "pages", "amount": -1.0 } } ]
  2. 在Sublime Text中,从菜单栏中选择Tools> New Plugin ...选项。
  3. 用以下内容替换新文件的内容: import sublime, sublime_plugin class ScrollLinesFixedCommand(sublime_plugin.TextCommand): """Must work exactly as builtin scroll_lines command, but without moving the cursor when it goes out of the visible area.""" def run(self, edit, amount, by="lines"): # only needed if one empty selection if by != "lines" or (len(self.view.sel()) == 1 and self.view.sel()[0].empty()): maxy = self.view.layout_extent()[1] - self.view.line_height() curx, cury = self.view.viewport_position() if by == "pages": delta = self.view.viewport_extent()[1] else: delta = self.view.line_height() nexty = min(max(cury - delta * amount, 0), maxy) self.view.set_viewport_position((curx, nexty)) else: self.view.run_command("scroll_lines", {"amount": amount})
  4. 将文件保存到〜/ Library / Application Support / Sublime Text 2 / Packages / ScrollLinesFixed /。您需要创建ScrollLinesFixed文件夹。
  5. 没有第5步。

4
投票

只是我的2美分,但我有我的设置向上或向下滚动以下内容:

{ "keys": ["super+up"], "command": "scroll_lines", "args": {"amount": 1.0} },
{ "keys": ["super+down"], "command": "scroll_lines", "args": {"amount": -1.0} }

我使用的是Mac,因此“超级”键是命令键,它是空格键左侧(或右侧)的第一个键。不确定Windoze上的等价物是什么;也许这将是“开始”键或其他东西。无论如何,工作就像一个魅力。

© www.soinside.com 2019 - 2024. All rights reserved.