V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
CrazyRain0001
V2EX  ›  问与答

有什么好的代码文件内容自动整理工具吗?

  •  
  •   CrazyRain0001 · 2019-11-26 15:04:50 +08:00 · 1532 次点击
    这是一个创建于 1585 天前的主题,其中的信息可能已经有所发展或是发生改变。

    包含功能

    • 文件格式全部转为 utf8 等
    • 将所有 tab 缩进改为 4 个空格
    • 删除行尾多余空格
    • 自动对齐
    • 去掉或添加行尾的'\r'
    • ...
    10 条回复    2019-11-26 17:51:44 +08:00
    rain0002009
        1
    rain0002009  
       2019-11-26 15:48:48 +08:00
    prettier ?
    Rwing
        2
    Rwing  
       2019-11-26 15:53:31 +08:00
    vs 有个功能叫 code cleanup
    hei1000
        3
    hei1000  
       2019-11-26 17:07:31 +08:00
    写脚本?

    我的一个简单的命令行, 放在脚本里面可以添加一些其他的功能, 当然了, 要利用自己的 vim/nvim 配置比如保存文件时"删除行尾多余空格"
    ~~~
    nvim -es -c 'args ./**/*.cpp | argdo execute "normal gg=G" | update'
    ~~~
    gwy15
        4
    gwy15  
       2019-11-26 17:20:58 +08:00
    看你啥语言了,
    C 系:clang-format
    py:autopep8
    CrazyRain0001
        5
    CrazyRain0001  
    OP
       2019-11-26 17:30:02 +08:00
    @rain0002009 看了下介绍,是 js 代码格式化的?
    CrazyRain0001
        6
    CrazyRain0001  
    OP
       2019-11-26 17:30:53 +08:00
    @Rwing 没找到
    Rwing
        7
    Rwing  
       2019-11-26 17:31:58 +08:00
    CrazyRain0001
        8
    CrazyRain0001  
    OP
       2019-11-26 17:33:09 +08:00
    @hei1000 自动对齐和文件格式转换感觉用脚本不好写
    CrazyRain0001
        9
    CrazyRain0001  
    OP
       2019-11-26 17:50:14 +08:00
    @Rwing 好吧~看了下貌似 vs2019 的 c#才支持的

    >For C# code files, Visual Studio 2019 has a Code Cleanup button at the bottom of the editor (keyboard: Ctrl+K, Ctrl+E) to apply code styles from an EditorConfig file or from the Code Style options page. If an .editorconfig file exists for the project, those are the settings that take precedence.
    hei1000
        10
    hei1000  
       2019-11-26 17:51:44 +08:00
    @CrazyRain0001 #8

    看我上面"normal gg=G"就是自动对齐的

    格式转换的话利用 iconv 之类的命令转换, 不过貌似 iconv 得提供源 Encoding, 你先获取一下, 全都放到脚本里面就行了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4671 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 09:48 · PVG 17:48 · LAX 02:48 · JFK 05:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.