【Sublime详解】mac最好用的编辑器-配置-插件- Alignment-费元星

########################

先同步下自己用了8年多的配置:

mac 打开配置快捷键:command+,    逗号

// Settings in here override those in "Default/Preferences.sublime-settings",
// and are overridden in turn by syntax-specific settings.
{
 // 中文错位解决办法
  "font_options":["gdi"],
 // 每次打开文件,在一个窗口打开
 "open_files_in_new_window": false, 
 // 鼠标失去聚焦后,自动保存
 "save_on_focus_lost": true,
 // 自动换行
 "word_wrap": "auto",
 //显示制表符  会吧空格也显示出来
 "draw_white_space":"all",
 "hot_exit": true,
 "remember_open_files": true,
 "update_check": false,

 "color_scheme": "Packages/Color Scheme - Default/Breakers.sublime-color-scheme",
 "font_size": 12,
 "ignored_packages": ["Vintage",],
 "index_files": true,
 "alignment_prefix_chars":[
     " ","+","--","-","//","/",".","*","="
    ],
  // 当前行高亮
  "highlight_line": false,
  // 窗口右下角显示打开文件的编码
  "show_encoding": true, 
  // 显示行号右侧的代码段闭合展开三角号
  "fade_fold_buttons": false, 
  //显示全路径
  "show_full_path": true, 
   //保存的时候把无用的空格去掉
  "trim_trailing_white_space_on_save": true,
  // 双击文件 在tab里打开 不是window
  /*"open_files_in_new_window": false,*/
  //加粗文件夹名称
  "bold_folder_labels": true,
  // 一个tab 4个空格
  "tab_size":4,
  "font_face": "Ubuntu Mono",





}

##########################

#Sublime Text 编辑器 插件 之

"Sublime Alignment" 详解

Sublime Alignment 主要用于代码对齐,最新版据说已经集成了这个插件。 下载地址:


插件安装方式、以及较好的插件推荐,如下:

Sublime Text 2 入门及技巧 | Lucifr

编码神器 Sublime Text 包管理工具及扩展大全 - 开源中国社区


Mac上的设置文件位置:
左上角Sublime Text -> Preferences -> Package Settings ->Alignment 如果没有最后的"Alignment"选项,说明你还没有安装此插件。

这里面有5个选项:

  • Settings- Default
  • Settings- User
  • Settings- Syntax Specific - User
  • Key Bildings - Default
  • Key Bildings - User

带有后缀Default的,为默认设置,每次升级插件都会重置这里的设置。所以尽量不要修改这里,否则升级会丢失你原先的设置。

带有后缀User的,为用户自定义设置,你可以把Default里面的设置全部复制一份到这里,然后再修改,这里存在的设置选项会覆盖Default里面的,即User的优先级更高。

Key Bildings为快捷键设置,默认的快捷键很有可能因为和其他快捷键冲突而无效, 所以及可以在Key Bildings - User里重新设置(格式可以仿照Default里的写法)。
此快捷键是用来 实现对齐的。


这个插件的默认设置Settings- Default如下:

{
    // If the indent level of a multi-line selection should be aligned
    "align_indent": true,

    // If indentation is done via tabs, set this to true to also align
    // mid-line characters via tabs. This may cause alignment issues when
    // viewing the file in an editor with different tab width settings. This
    // will also cause multi-character operators to be left-aligned to the
    // first character in the operator instead of the character from the
    // "alignment_chars" setting.
    "mid_line_tabs": false,

    // The mid-line characters to align in a multi-line selection, changing
    // this to an empty array will disable mid-line alignment
    "alignment_chars": ["="],

    // If the following character is matched for alignment, insert a space
    // before it in the final alignment
    "alignment_space_chars": ["="],

    // The characters to align along with "alignment_chars"
    // For instance if the = is to be aligned, there are a number of
    // symbols that can be combined with the = to make an operator, and all
    // of those must be kept next to the = for the operator to be parsed
    "alignment_prefix_chars": [
        "+", "-", "&", "|", "<", ">", "!", "~", "%", "/", "*", "."
    ]
}

##参数详解

下面为原始测试数据

int aa = 1;
    char bb = 'a';
        float fff = 2;
unsigned int d = 1;

###"align_indent":

开关量,默认为true,

  • true,则把选择的多行的 不同缩进级别也变成相同的缩进(最大的缩紧级别),结果如下:
        int aa = 1;
        char bb = 'a';
        float fff = 2;
        unsigned int d = 1;
  • flase,只是对齐,不改变缩进级别
int aa            = 1;
    char bb       = 'a';
        float fff = 2;
unsigned int d    = 1;

###"mid_line_tabs"

开关量,默认为false。
如果你的文本是使用Tab键缩进排版,设置该变量为true时,那么该插件在对齐文本的时候也使用Tab键来对齐缩进。
但是这样可能会出现问题,因为Tab键在不同的编辑器上代表的空格数可能不同(Sublime 是代表4个空格), 当你使用别的编辑器打开该文件时,简而言之,就是排版可能就不是对齐的了。


###"alignment_chars"

对齐字符

这是一个数组,可以这样设置多个字符:alignment_chars": ["=","*","a"]
默认只有“=”字符,即alignment_chars": ["="]
数组里面的字符就是放在中线对齐的字符。
如下面都把“=”排成一列中线对齐

        int aa         = 1;
        char bb        = 'a';
        float fff      = 2;
        unsigned int d = 1;

例如设置里增加“*”号,即:alignment_chars": ["=","*"]
结果如下:

原文:

int *aa = 1;
    char *bb = 'a';
        float *fff = 2;
unsigned int *d = 1;

排列对齐后:(把“*”号排成对齐的一列)

        int          *aa = 1;
        char         *bb = 'a';
        float        *fff = 2;
        unsigned int *d = 1;

###"alignment_space_chars"

和**"alignment_chars"**一样,也是数组格式 默认值包含“=”号,即:alignment_space_chars": ["*","="]

就是这个数组包含上面**"alignment_chars"里的字符, 对齐后,在其前面增加一个空格。
如果这里不包含
"alignment_chars"**里的字符,对齐后,在其前面没有空格。

可以这样说, **"alignment_space_chars"数组是"alignment_chars"**数组的子集。

原文还在文章的起始处,这里设置包含“=”,
alignment_space_chars": ["="]
结果如下:

        int aa         = 1;
        char bb        = 'a';
        float fff      = 2;
        unsigned int d = 1;

这里设置不包含任何字符,
alignment_space_chars": []
结果如下:

        int aa        = 1;
        char bb       = 'a';
        float fff     = 2;
        unsigned int d= 1;

###"alignment_prefix_chars"

即:前缀字符 默认设置:
"alignment_prefix_chars": ["+", "-", "&", "|", "<", ">", "!", "~", "%", "/", "*", "."]

对齐字符(即alignment_chars"里的字符),可以拥有前缀字符。
例如"="号字符前可以拥有以上字符作为前缀。

原文设置如下:(这里的前缀字符有 "!"、"<"符号)

int aa = 1;
    char bb != 'a';
        float fff <= 2;
unsigned int d = 1;

对齐后如下:(即把前缀字符+对齐字符一起当作对齐字符来对待)

        int aa         = 1;
        char bb        != 'a';
        float fff      <= 2;
        unsigned int d = 1;

##总结

可按照以上的参数说明,自己增加对齐的字符来增强功能。
我一般需要在对齐字符前面增加一个空格,
所以我一般就保持alignment_chars 数组和 alignment_space_chars数组一致。即在所有的对齐字符前面都增加一个空格。

  • 18
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

未来星_狒狒

有问题随时交流Q9715234

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值