作者:shede333
主頁:http://my.oschina.net/shede333
版權聲明:原創文章,版權聲明:自由轉載-非商用-非衍生-保持署名 | [Creative Commons BY-NC-ND 3.0][]
#Sublime Text 編輯器 插件 之
"Sublime Alignment" 詳解
Sublime Alignment 主要用於代碼對齊,最新版據說已經集成了這個插件。 下載地址:
插件安裝方式、以及較好的插件推薦,如下:
編碼神器 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
