ST2 键盘映射:“expand_selection"的参数; [英] ST2 Keymap: Args for "expand_selection"
问题描述
有谁知道如何编辑 Sublime Text 2 中的expand_selection"键映射,以便它只选择当前行而不是后面的换行符?
Does anyone know how to edit the "expand_selection" keymap in Sublime Text 2 so that it only selects the current line and not the line break that follows it?
默认的键盘映射是这样的:
The default keymap is this:
{ "keys": ["ctrl+l"], "command": "expand_selection", "args": {"to": "line"} }
{ "keys": ["ctrl+l"], "command": "expand_selection", "args": {"to": "line"} }
问题在于,当您选择该行并开始用新代码替换它时,它后面的行会向上移动到当前行.
The problem is that when you select the line and begin replacing it with new code, the line that follows it moves up to the current line.
我假设您将args"部分中的line"替换为其他内容,但我似乎无法在任何地方找到此文档.
I assume you replace "line" in the "args" section with something else, but I can't seem to find this documented anywhere.
推荐答案
我也找不到任何选择当前行而不选择下一行的示例/文档.幸运的是,我们可以创建一个执行此操作的命令.
I also could not find any example/documentation of selecting the current line without selecting the next line. Fortunately we can make a command that does this.
- 创建一个文件
User/my_utilities.py
.我把我所有的随机自行开发的 ST 命令贴在这里. 坚持下去:
- Create a file
User/my_utilities.py
. I stick all my random self-developed ST commands here. Stick this in it:
import sublime, sublime_plugin
class MyExpandSelectionToLine(sublime_plugin.TextCommand):
def run(self, edit):
regions = []
for s in self.view.sel():
line = self.view.line(sublime.Region(s.begin(), s.end()))
if line.end() == s.end():
# we're at the end of a line, so select the next line
line = self.view.line(sublime.Region(s.end(), s.end() + 1))
regions.append(line)
for r in regions:
self.view.sel().add(r)
在您的 User .sublime-keymap 文件中,添加:
In your User .sublime-keymap file, add this:
`{ "keys": ["super+l"], "command": "my_expand_selection_to_line" }`
如果在 Windows 上你需要 ["ctrl+l"]
而不是 ["super+l"]
If on Windows you'll want ["ctrl+l"]
instead of ["super+l"]
这会覆盖默认的命令绑定,用于选择一行来运行我们刚刚编写的新命令.
This overrides the default command binding for selecting a line to run the new command we just wrote.
这篇关于ST2 键盘映射:“expand_selection"的参数;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!