V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Zizpop
V2EX  ›  Visual Studio Code

VsCode 有没有办法忽略文件的最后一个扩展名(file.ext.bk->file.ext)

  •  
  •   Zizpop · 29 天前 · 913 次点击
    平时会创建 bk 、deprecated 结尾的文件,但是 vscode 打开这些文件时会无法识别对应的文件类型。
    比如:
    1. hellworld.cc.bk 识别为 bk 类型的文件
    2. README.md.bk 识别为 bk 类型的文件

    有没有办法识别文件的最后一个扩展名为特定单词后忽略它,并使用倒数第二个扩展名?
    比如:
    1. helloworld.cc.bk 识别为 C++类型
    2. README.md.bk 识别为 markdown 类型
    9 条回复    2024-03-29 13:42:12 +08:00
    iSecret
        1
    iSecret  
       29 天前
    看了下文件关联,似乎不支持正则,有点悬。
    Zizpop
        2
    Zizpop  
    OP
       29 天前
    对了,后缀为 in 的文件一般是模版文件,也会有这样的需求
    Zizpop
        3
    Zizpop  
    OP
       29 天前
    @iSecret 扩展有办法做到吗?
    iSecret
        4
    iSecret  
       29 天前
    还有个思路,把你常用可能需要备份的文件列下来,比如:

    ```
    html
    go
    php
    java
    jar
    war
    ```

    然后通过正则 `(.*)` 替换为 `"*.$1.bak": "$1",` 生成关联配置,最后导入到 `settings.json` 的 `files.associations` 配置里,测试了一下可行。
    Zizpop
        5
    Zizpop  
    OP
       29 天前
    @iSecret 现在基本上就是这么做的,主要是这样不太灵活
    Zizpop
        6
    Zizpop  
    OP
       29 天前
    https://github.com/Microsoft/vscode/issues/40285

    找到一个相关的 issue ,官方的回复是自行写扩展实现
    Trim21
        7
    Trim21  
       29 天前 via Android
    @iSecret 支持通配符
    Trim21
        8
    Trim21  
       29 天前 via Android
    Zizpop
        9
    Zizpop  
    OP
       29 天前
    @Trim21 现在就是用的通配符

    ```javascript
    {
    "files.associations": {
    "*.qs.in": "javascript",
    "*.sh.in": "shellscript",
    "*.nsh.in": "nsis"
    }
    }
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1289 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 17:41 · PVG 01:41 · LAX 10:41 · JFK 13:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.