如何搜索选定的文本?

mau*_*oni 2 visual-studio-code vscode-settings

如何在当前文件中搜索所选文本而不必复制 / ctrl-f / paste

澄清一下 Ultraedit 有这种行为。当按下F3并且没有选定的文本时,它执行最后一次搜索,如果有选定的文本,则它在当前文件中搜索选定的文本。

Ale*_*ers 6

启用editor.find.seedSearchStringFromSelection设置,如下所示。当您按 ctrl+f 时,这将导致自动搜索突出显示的文本。

在此处输入图片说明


Jac*_*Yeh 4

Ultraedit-way 搜索是我最喜欢的,而且非常方便:单个“F3”键即可处理所有内容。

其缺点Ctrl+D是:它不能环绕搜索。

需要明确的是,Ultraedit方式搜索的定义是:当按下F3并且没有选定的文本时,它执行最后一次搜索,如果有选定的文本,则在当前文件中搜索选定的文本。

这是绝对 100% 兼容 Ultraedit 方式搜索的解决方案:

  • 选择文本后,执行 nextSelectionMatchFindAction
  • 当没有选择文本时,执行 nextMatchFindAction
  • 单身人士F3可以同时完成上述两项工作。
  • Shift+F3保持原样:查找上一个

因此keybindings.json可以添加以下行来禁用原始F3Ctrl+F3功能,并F3在选择文本和未选择文本时添加两个新功能。

{
    "key": "f3",
    "command": "editor.action.nextSelectionMatchFindAction",
    "when": "editorFocus && editorHasSelection"
},
{
    "key": "ctrl+f3",
    "command": "-editor.action.nextSelectionMatchFindAction",
    "when": "editorFocus"
},
{
    "key": "f3",
    "command": "editor.action.nextMatchFindAction",
    "when": "editorFocus && !editorHasSelection"
},
{
    "key": "f3",
    "command": "-editor.action.nextMatchFindAction",
    "when": "editorFocus"
}
Run Code Online (Sandbox Code Playgroud)

还有一件事需要解决:按下 时F3,会出现搜索对话框,并且每个匹配的文本都会突出显示,ESC搜索完成后您可以按下 关闭搜索对话框。

更新@2021/1/25 如果有人想像Shift+F3一样聪明地工作F3,请将以下行添加到 keybindings.json

{
    "key": "shift+f3",
    "command": "editor.action.previousSelectionMatchFindAction",
    "when": "editorFocus && editorHasSelection"
},
{
    "key": "shift+f3",
    "command": "editor.action.previousMatchFindAction",
    "when": "editorFocus && !editorHasSelection"
},
{
    "key": "shift+f3",
    "command": "-editor.action.previousMatchFindAction",
    "when": "editorFocus"
},
Run Code Online (Sandbox Code Playgroud)