Sublime Text 2:如何向上/向下翻页而不移动光标 [英] Sublime Text 2: How to Page Up/Down without moving the cursor

查看:2731
本文介绍了Sublime Text 2:如何向上/向下翻页而不移动光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OS X 10.8.4使用ST2。当我使用Home和End键时,视口移动,光标单独留下。这是标准的Mac行为,我期望的。

I'm on OS X 10.8.4 using ST2. When I use the Home and End keys, the viewport moves and the cursor is left alone. This is standard Mac behavior, and what I'd expect.

但是,当我使用Page Up(pageup / pgup)和Page Down(pagedown / pgdn)光标随视口一起移动。这不是其他Mac应用程序的行为,我想把光标留给这些键太孤独。

However, when I use Page Up (pageup/pgup) and Page Down (pagedown/pgdn), the cursor moves along with the viewport. This is not how other Mac apps behave, and I'd like the cursor to be left alone for these keys too.

我已经能够得到这个half-通过添加到我的键绑定工作:

I've been able to get this half-working by adding this to my key bindings:

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

但是,这里的金额是硬编码的。它看起来像viewport_extent会得到我的视口的高度,但我如何使用从键绑定文件?这是甚至正确的解决方案吗?

However, the amounts there are hard-coded. It looks like viewport_extent will get me the height of the viewport, but how can I use that from within the key bindings file? Is this even the correct solution for this? I feel like it's an awful lot of work to go to to get this behavior.

提前感谢。

推荐答案

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

To do this requires a text plugin. Thanks to user bizoo on the ST Forums, you don't have to write this yourself:

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

这与我预期的一样。

这不清楚,并且还使用了一个可能会在将来死亡的裸网址。

Update: This isn't clear, and also uses a bare URL which could conceivably die in the future. So here's a more complete explanation of what you need to do.


  1. 将这四行添加到Sublime Text 2>首选项>键Bindings - 用户,在文件中已有的任何方括号内:

  1. Add these four lines to Sublime Text 2 > Preferences > Key Bindings - User, inside any square brackets that are already in the file:

[
    { "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 } }
]


  • 在Sublime Text中,选择工具>

  • 使用以下内容替换新文件的内容:

  • Within Sublime Text, choose the Tools > New Plugin… option from the menu bar.
  • Replace the contents of the new file with this:

    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})
    

    / li>

  • 将文件保存到〜/ Library / Application Support / Sublime Text 2 / Packages / ScrollLinesFixed /。您需要创建ScrollLinesFixed文件夹。

  • 没有步骤5。

  • Save the file to ~/Library/Application Support/Sublime Text 2/Packages/ScrollLinesFixed/. You will need to create the ScrollLinesFixed folder.
  • There's no step 5.
  • 这篇关于Sublime Text 2:如何向上/向下翻页而不移动光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆