作者: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. TSynAuthentication SESSION验证

    TSynAuthentication SESSION验证 服务端维护的SESSIONS,实质上是一个array of integer,保存的是客户端的SESSIONID. SESSIONID可以由客户 ...

  2. c#中的??运算符

    注意啦,c#中的??运算符是和?:运算符是不同的,这两者是有区别的. ??运算符称为null合并运算符,用于定义null值的类型和引用类型的默认值. 只当运算符的左操作数不为 null,此运算符将返回 ...

  3. 一个简单的WebService服务

    现在,网上提供的免费的webservice服务的网站: http://www.webxml.com.cn/ 从扩展名上看,是 .net构建的网站. 看看功能的实现效果: 需求:我们要远程调用手机号归属 ...

  4. synchronized 线程同步

    synchronized  通常用来形容一次方法的调用,调用一旦开始,调用者必须等到方法调用返回后,才能继续执行后续的操作. 1.demo package demo1; public class My ...

  5. [转]SSIS ProtectionLevel 对包中敏感数据的访问控制

    本文转自:http://technet.microsoft.com/zh-cn/library/ms141747.aspx 为了保护 Integration Services 包中的数据,可以设置保护 ...

  6. 删除其他硬盘的Windows文件夹

    删除其他硬盘的Windows文件夹 学习了:https://blog.csdn.net/drbing/article/details/50881461 有效果,必须先改文件夹的所属,然后才能修改权限: ...

  7. 转: RSA原理 阮一峰的博客

    转:http://www.ruanyifeng.com/blog/2013/06/rsa_algorithm_part_one.html 讲的非常细致,易懂.

  8. 扩展Jquery方法创建LigerUI Grid

    ///** //*封装jquery get请求ajax //*author:叶明龙 //*time:2012-12-10 //*/ function getAjax(url, para, fn) { ...

  9. Out of office 模板

    I am out of the office until 0X/0X/201X. I will be checking my email regularly.  Please leave a comp ...

  10. 各种字符编码方式详解及由来(ANSI,UNICODE,UTF-8,GB2312,GBK)

    一直对字符的各种编码方式懵懵懂懂,什么ANSI UNICODE UTF-8 GB2312 GBK DBCS UCS……是不是看的很晕,假如您细细的阅读本文你一定可以清晰的理解他们.Let's go! ...