最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【基本解决】VSCode中排除某些文件只显示某些类型的文件

文件 crifan 1764浏览 0评论
需求:
就是好比打开一个大工程,比如内核,里面有很多文件类型,我只想看到.c .cpp .h文件,中间文件隐藏
我上次试了只能自己写规则隐藏
应该是打开过滤,类似si,我只添加需要的文件到project
这个vs只能打开文件夹吧
此处去研究看看
vscode hidden some file
vscode settings – How do I hide certain files from the sidebar in Visual Studio Code? – Stack Overflow
"files.exclude": {
    "node_modules/": true
}

"files.exclude": {
    "**/._*": true
}
目前发现是:
Code-》首选项-》设置
搜:
exclude
找到
file.exclue
然后去故意试试:
排除此处的csv的文件
所以去加上设置:
**/*.csv
效果:
可以实现:不显示所有csv的文件
另外,对于:
只显示某些特定类型的文件,比如.c .cpp .h
其他都排除掉
感觉应该需要用到!感叹号的写法
但是去试了试:
!**/*.py
结果没用:
其他非py的,比如txt还会显示
看到官网是
Basic Editing in Visual Studio Code
提到
” !example will skip searching any folder or file named example. Use ,to separate multiple patterns. Paths must use forward slashes. You can also use glob syntax:
* * to match one or more characters in a path segment
* ? to match on one character in a path segment
* ** to match any number of path segments, including none
* {} to group conditions (for example {**/*.html,**/*.txt} matches all HTML and text files)
* [] to declare a range of characters to match (example.[0-9] to match on example.0, example.1, …)”
去找找,是不是:或许有file.include的选项?可以实现上述需求?
Visual Studio Code User and Workspace Settings
  // Configure glob patterns for excluding files and folders. For example, the files explorer decides which files and folders to show or hide based on this setting.
  "files.exclude": {
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true
  },

  // Configure glob patterns of file paths to exclude from file watching. Patterns must match on absolute paths (i.e. prefix with ** or the full path to match properly). Changing this setting requires a restart. When you experience Code consuming lots of cpu time on startup, you can exclude large folders to reduce the initial load.
  "files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/*/**": true
  },

  // Configure glob patterns for excluding files and folders in searches. Inherits all glob patterns from the `files.exclude` setting.
  "search.exclude": {
    "**/node_modules": true,
    "**/bower_components": true,
    "**/*.code-search": true
  },
没搜到:
file.include
配置中也没有。
include的相关选项,没有需要的
How to Hide Unwanted Folders and Files in Visual Studio Code
看到
突然想到:
或许是:
此处**所有都true,然后.c .cpp .h是false
看看是否可以起到效果
.vscode/settings.json
{
    // Configure glob patterns for excluding files and folders. For example, the files explorer decides which files and folders to show or hide based on this setting.
    "files.exclude": {
        "**/*": true,
        "**/*.py": false
    }
}
结果:
都不显示了:
但是*.py没起到效果
看来被上面的规则覆盖了。
vscode glob patterns
Glob Patterns · ev3dev/vscode-ev3dev-browser Wiki
API: Support glob pattern “**/!(*.min).js” for file watchers · Issue #27051 · microsoft/vscode
**/!(*.min).js
去试试
VS Code API | Visual Studio Code Extension API
"**/*.(py,md)": true
也不支持。
"**/*.[!(py)])": true
也不行。
vscode.GlobPattern – Haxe externs for Visual Studio Code – API documentation
试了半天,试了各种
{
    // Configure glob patterns for excluding files and folders. For example, the files explorer decides which files and folders to show or hide based on this setting.
    "files.exclude": {
        // "*": true,
        // "**/*.(py,md)": true,
        // "**/*.[!(py)])": true,
        "**/*.{!py}": true,
        // "**/*": false,
    }
}
都不行。
算了。
另外,对于此处,去试试,排除掉:
所有的pyc文件
__pycache__的文件夹:
试了试,写法是:
        "**/*.pyc": true,
        "**/__*__": true,
可以把对应内容:
隐藏掉:
【总结】
此处,目前只能支持:
想要排除某些类型文件,比如log和txt
单独的2个规则:
"**/*.log": true,
"**/*.txt": true,
放在一起的一条规则:
"**/*.{log,txt}": true,
完整配置文件:
.vscode/settings.json
{
    // Configure glob patterns for excluding files and folders. For example, the files explorer decides which files and folders to show or hide based on this setting.
    // https://code.visualstudio.com/api/references/vscode-api#GlobPattern

    
    
"**/*.{log,txt}": true,
    }
}
即可实现:
排除特定的某些类型的文件。

转载请注明:在路上 » 【基本解决】VSCode中排除某些文件只显示某些类型的文件

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.111 seconds, using 20.57MB memory