Sublime Text:在选择中查找和替换

Jel*_*Cat 23 sublime-text-2

Sublime Text 2 是否允许用户执行查找和替换,仅限于当前选择?

我应该认为它必须,只是我在多次搜索后无法找到如何执行它。

Hen*_*nno 25

ST2中有一个按钮。

截屏

  • @TheStoryCoder 是的,这不是键盘快捷键,这很愚蠢,但事实证明制作一个快捷键很容易,只是命令的名称没有记录,但我很幸运并且猜对了。这是添加到用户键绑定的代码:{ "keys": ["alt+y"], "command": "toggle_in_selection", "context": [ { "key": "setting.is_widget", "operator" : "equal", "operand": true } ] }, (5认同)
  • 没错,有一个按钮。但是你如何使用它呢?特别是,你如何设置“选择”?根据我的经验,ST2 使用您打开搜索栏时的选择。因此,如果栏已经打开,您必须先关闭它 (Esc),然后选择要检查的文本范围,然后再次打开它(Ctrl+F 或 Ctrl+H)。专业提示:如果选择跨越多行,它不会替换您当前的搜索表达式。 (4认同)
  • 在 Mac 上使用 Cmd+Opt+F 打开查找和替换控制台。 (3认同)
  • 我完全不明白为什么“选择中”没有键盘快捷键,尤其是因为所有其他选项都有!我真的必须将手移到鼠标才能启用它吗?似乎违背了所有 ST 代表......(我正在使用 ST3) (2认同)

Owe*_*_AR 8

以下是您需要添加到用户键绑定的内容:

{ "keys": ["alt+y"], "command": "toggle_in_selection", "context":
    [
        { "key": "setting.is_widget", "operator": "equal", "operand": true }
    ]
},
Run Code Online (Sandbox Code Playgroud)

是的,没有默认的键绑定集是愚蠢的。

命令名称“ toggle_in_selection”也没有记录,但我猜到了,而且很幸运。


编辑添加:

/*
btw, the way i want to use find by default
(actually, i use replace by default, but same dif),
is for "in_selection" to be true by default,
*unless* the selection is empty.
(
the default is that "in_selection" is *false* by default,
unless the selection contains a newline.
)
i finally got around to digging up how to get that,
which is apparently by changing the *keybindings* you use to pop open the find(/replace) panel?
*/
    { "keys": ["ctrl+f"], "command": "show_panel", "args": {"panel": "replace", "in_selection": true}},
    { "keys": ["ctrl+f"], "command": "show_panel", "args": {"panel": "replace", "in_selection": false},
    "context":
        [
            { "key": "selection_empty", "operator": "equal", "operand": true}
        ]
    },
Run Code Online (Sandbox Code Playgroud)


小智 7

如果您的选择包含换行符,“选择范围内”按钮将自动激活 - 在 ST2 上

不幸的是,智能激活在 ST3 上丢失了。你可以在这里跟进http://www.sublimetext.com/forum/viewtopic.php?f=3&t=11679

  • 现在可以使用以下方法恢复此功能: "auto_find_in_selection": true (11认同)