Sublime Text:在选择范围内查找并替换

Sublime Text:在选择范围内查找并替换

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

我想这是必须的,只是我搜索了多次却仍未找到如何实现它。

答案1

ST2 中有一个用于该目的的按钮。

截屏

答案2

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

{ "keys": ["alt+y"], "command": "toggle_in_selection", "context":
    [
        { "key": "setting.is_widget", "operator": "equal", "operand": true }
    ]
},

是的,没有默认的键绑定设置,这很愚蠢。

另外,命令名称“ 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}
        ]
    },

答案3

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

不幸的是,ST3 上的智能激活功能已丢失。您可以在此处跟踪此事。http://www.sublimetext.com/forum/viewtopic.php?f=3&t=11679

答案4

(使用 Mac OS X 特定的快捷方式)替换some namenew name

  1. 将光标放在文本上方
  2. 查找some namecmdf,输入some name(有时需要按return
  3. 指定 replace: shiftcmdrtabtab以替换字段,类型new namereturn
  4. 重复altcmde直至完成。

相关内容