当使用 up 或 down 滚动自动完成列表时,如果你向任一方向走得太远(例如没有更多建议),列表将关闭。< / p>
我想要的行为是在到达终点而不是关闭时让列表换行。
通过分配此热键可以轻松修复向下滚动:
{ "keys": ["down"], "command": "auto_complete", "context":
[ { "key": "auto_complete_visible" } ]
},
这是因为auto_complete
命令具有内置功能,可以在每次调用时向下滚动,这就是热键的工作原理。
...但向上滚动是不同的。我尝试了大约20种不同的热键和宏组合但没有成功。
我几乎可以肯定,实现此行为的唯一方法是使用插件,但不幸的是我的Python技能级别为零。
如果重要,我用 ctrl + space 手动调用自动完成(自动弹出窗口被禁用)。
我正在使用Sublime Text 2。
答案 0 :(得分:10)
最佳解决方案:使用 auto_complete_cycle 设置(2015年3月26日添加):
2015年3月24日发布的Sublime Text新版本有一个新的设置,名为 auto_complete_cycle ,可以实现此行为。将其设置为true以迭代自动完成结果。
"auto_complete_cycle": true
最糟糕的旧解决方案:此自定义插件
我刚刚在 Linux Mint 中制作了适用于 Sublime Text 3 的插件。我没有在 Sublime Text 2 中对它进行测试,但认为插件系统是相同的,因此,它也适用于该版本。解决方法使用它并不太漂亮但有效。
import sublime, sublime_plugin
class UpArrowInAutoCompleteCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.settings().set('autoCompleteFlag',True)
self.view.settings().set('initialPoint', self.view.sel()[0].begin())
""" Move one line up """
self.view.run_command('move', {"by": "lines", "forward": False});
""" Auto-complete was opened and up arrow was pressed, so if the cursor changes
(on_selection_modified will be triggered) we have gone outside the list.
If we were not in the first element on_selection_modified will not be triggered, so
we turn of the flag"""
sublime.set_timeout(lambda: self.view.settings().set('autoCompleteFlag', False),300)
class AutoCompleteSelectionModifiedTriggerCommand(sublime_plugin.EventListener):
def on_selection_modified(self, view):
if view.settings().get('autoCompleteFlag'):
""" If the up arrow was pressed and on_selection_modified
has been triggered, then we know that we were in the first element
of the list and we hitted the up arrow"""
view.settings().set('autoCompleteFlag', False)
initialPoint = view.settings().get('initialPoint')
""" We don't know how many words the auto_complete has, so,
in order to calculate that number, we move down in the list
till we get outside the list. After that we make the list appear
again and move down n-1 times to go (and stay) to the last line """
view.sel().clear()
view.sel().add(initialPoint)
view.run_command('auto_complete')
numLines = 0
while view.sel()[0].begin() == initialPoint:
view.run_command('move', {"by": "lines", "forward": True})
numLines += 1
if numLines == 401:
return
if numLines == 0:
return
view.sel().clear()
view.sel().add(initialPoint)
view.run_command('auto_complete')
numLine = 0
while numLine < (numLines-1):
view.run_command('move', {"by": "lines", "forward": True})
numLine += 1
要使插件使用工具&gt;新插件并粘贴代码。然后将其保存在 Packages / User 文件夹中。您可以使用首选项&gt;浏览包来查找用户文件夹所在的 Packages floder。
为了使它工作,我添加到我的用户密钥绑定文件这个绑定(第二个是你自己的绑定):
{
"keys": ["up"],
"command": "up_arrow_in_auto_complete",
"context": [{
"key": "auto_complete_visible",
"operator": "equal",
"operand": true
}]
}, {
"keys": ["down"],
"command": "auto_complete",
"context": [{
"key": "auto_complete_visible"
}]
}
编辑:这是一个示例结果: