作者:shede333
主页:http://my.oschina.net/shede333
版权声明:原创文章,版权声明:自由转载-非商用-非衍生-保持署名 | [Creative Commons BY-NC-ND 3.0][]


#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数组一致。即在所有的对齐字符前面都增加一个空格。

转载自:https://my.oschina.net/shede333/blog/170536

Sublime Text 编辑器 插件 之 "Sublime Alignment" 详解的更多相关文章

  1. 全网最详细的Sublime Text 3的激活(图文详解)

    不多说,直接上干货! 前期博客 全网最详细的Windows里下载与安装Sublime Text *(图文详解) ZYNGA INC. User License EA7E- 927BA117 84C93 ...

  2. 如何安装 Sublime text 编辑器相关的插件

    Sublime是一个伟大的编辑器,具有可靠的基础功能,使编写代码变得愉快.您可以安装一个包管理器,以便于安装插件和添加新功能. 为什么使用包管理器(package manager) 包管理器可以方便地 ...

  3. 开发者最常用的 8 款 Sublime Text 3 插件

    转载于:http://www.itxuexiwang.com/a/liunxjishu/2016/0228/177.html?1456925631Sublime Text作为一个尽为人知的代码编辑器, ...

  4. Sublime Text 最佳插件列表(转)

    Package Control 安装方法 首先通过快捷键 ctrl+` 或者 View > Show Console 打开控制台,然后粘贴相应的 Python 安装代码. Sublime Tex ...

  5. 8款实用Sublime text 3插件推荐

    Sublime Text作为一个尽为人知的代码编辑器,其优点不用赘述.界面整洁美观.文本功能强大,且运行速度极快,非常适合编写代码,写文章做笔记.Sublime Text还支持Mac.Windows和 ...

  6. 推荐!Sublime Text 最佳插件列表

    本文由 伯乐在线 - 艾凌风 翻译,黄利民 校稿.英文出处:ipestov.com.欢迎加入翻译组. 本文收录了作者辛苦收集的Sublime Text最佳插件,很全. 最佳的Sublime Text ...

  7. Sublime Text 2 插件

    一直以来写代码都是用的EditPlus,也尝试了一段时间学习Vim这神器,后来因为使用不习惯还是改回了原来的EditPlus.前几天朋友想我推荐了Sublime Text 2,喜欢尝鲜我的肯定是不会放 ...

  8. 转: sublime text常用插件和快捷键

    Sublime Text 2是一个轻量.简洁.高效.跨平台的编辑器.博主之前一直用notepdd++写前端代码,用得也挺顺手了,早就听说sublime的大名,一直也懒得去试试看,认为都是工具用着顺手就 ...

  9. Sublime Text 最佳插件列表

    http://blog.jobbole.com/79326/ 推荐!Sublime Text 最佳插件列表 2014/07/25 · 工具与资源 · 26.1K 阅读 · 2 评论 · Sublime ...

随机推荐

  1. synchronized 线程同步-类级别锁定

    1.demo 说明:代码中通过 printNum 方法传入参数判断 a.b 分别对 num 这个参数的值进行了修改. package demo1; import sun.applet.Main; pu ...

  2. [转]Sql Server 主从数据库配置

    本文转自:http://www.cnblogs.com/yukaizhao/archive/2010/06/02/sql-server-master-slave-mode.html 网站规模到了一定程 ...

  3. CSS权重的等级划分

    CSS权重 CSS权重指的是样式的优先级,有两条或多条样式作用于一个元素,权重高的那条样式对元素起作用,权重相同的,后写的样式会覆盖前面写的样式. 权重的等级 可以把样式的应用方式分为几个等级,按照等 ...

  4. Java内存缓存

    1.缓存为什么要存在 应用服务器资源是有限的,数据库每秒中接受请求的次数也是有限的.如果利用有限的资源来提供尽可能大的吞吐量呢,一个办法:减少计 算量,缩短请求流程(减少网络io或者硬盘io),这时候 ...

  5. Item 33: 避免覆盖(hiding)“通过继承得到的名字”

    莎士比亚有一个关于名字的说法."What's in a name?" 他问道,"A rose by any other name would smell as sweet ...

  6. http://www.cnblogs.com/jqyp/archive/2010/08/20/1805041.html

    http://www.cnblogs.com/jqyp/archive/2010/08/20/1805041.html

  7. 【android开发】10款实用的Android UI工具,非常有用!

    移动应用的UI设计就好似达摩克利斯之剑,一方面,一个视觉.交互.体验良好的UI可以加强应用在用户心目中的形象和识别性.而另一方面,一个体验糟糕的UI设计不仅无法让用户沉浸在应用中,还会造成用户对应用产 ...

  8. mac软件下载

    mac软件下载 http://www.pc6.com/mac/ https://www.macx.cn/

  9. EffectiveJava(30) -- 全面解析enum类型

    --在大多数项目中,我们会经常使用int类型来声明final类型的常量,它在不考虑安全的情况下确实能满足我们绝大多数的需求.但是在JDK1.5版本发布之后,声明一组固定的常量组成合法值的类型就建议使用 ...

  10. JVM基础(1)——内存模型

    转载:http://blog.csdn.net/weitry/article/details/53264262 系列文章规划: JVM基础(1)——内存模型 JVM基础(2)——内存管理 JVM基础( ...