左上角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數組一致。即在所有的對齊字符
前面都增加一個空格。
原文地址