最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to Add a Shortcut for 'Find File References' in VS Code and Exclude Specific Folders? - Stack Overflow

programmeradmin3浏览0评论

When you right-click a file in Visual Studio Code, you have the option 'Find File References.' Is it possible to add a keyboard shortcut to that action? Additionally, I would like to exclude certain folders when the shortcut is used.

I tried adding the following to my keybindings.json:

{
  "key": "ctrl+shift+f",
  "command": "editor.action.findFileReference",
  "when": "editorTextFocus"
}

However, the command editor.action.findFileReference doesn't seem to exist. Could it be named differently? I haven't been able to find the correct command.

Also, if it's possible to exclude a folder from the search, it would be helpful. Some folders, like /node_modules, are quite large and make the command slow. How can I achieve both adding the shortcut and excluding specific folders from the search?

When you right-click a file in Visual Studio Code, you have the option 'Find File References.' Is it possible to add a keyboard shortcut to that action? Additionally, I would like to exclude certain folders when the shortcut is used.

I tried adding the following to my keybindings.json:

{
  "key": "ctrl+shift+f",
  "command": "editor.action.findFileReference",
  "when": "editorTextFocus"
}

However, the command editor.action.findFileReference doesn't seem to exist. Could it be named differently? I haven't been able to find the correct command.

Also, if it's possible to exclude a folder from the search, it would be helpful. Some folders, like /node_modules, are quite large and make the command slow. How can I achieve both adding the shortcut and excluding specific folders from the search?

Share Improve this question edited Mar 9 at 11:24 Spara 31 bronze badge asked Mar 9 at 6:04 SevilaSevila 3231 gold badge5 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The command is extension-specific. The builtin extensions in VS Code provide it for Markdown and TypeScript/JavaScript. For TS/JS, see How to find all references of a selected module in VS Code?. TL;DR: use the typescript.findAllFileReferences command. For Markdown, use markdown.findAllFileReferences.

Usage for TS/JS would look like this:

{
    "key": "ctrl+b", // TODO: change to whatever you want
    "command": "typescript.findAllFileReferences",
    "when": "(editorLangId == typescript || editorLangId == javascript)",
},

(No need to specify a file argument because the command itself defaults to the active text editor, and in any case, at the time of this writing, you can't use variable references in keybindings).


Also, if it were possible to exclude a folder from the search, it would be helpful, since some folders, like /node_modules, are quite heavy, which makes the command slow.

You want the search.exclude setting.

发布评论

评论列表(0)

  1. 暂无评论