Sublime Text 編輯器 插件 之 "Sublime Alignment" 詳解

做者:shede333
主頁:http://my.oschina.net/shede333
版權聲明:原創文章,版權聲明:自由轉載-非商用-非衍生-保持署名 | [Creative Commons BY-NC-ND 3.0][]sublime-text


#Sublime Text 編輯器 插件 之數組

"Sublime Alignment" 詳解

Sublime Alignment 主要用於代碼對齊,最新版聽說已經集成了這個插件。 下載地址:編輯器


插件安裝方式、以及較好的插件推薦,以下:工具

Sublime Text 2 入門及技巧 | Lucifr測試

編碼神器 Sublime Text 包管理工具及擴展大全 - 開源中國社區this


Mac上的設置文件位置:
左上角Sublime Text -> Preferences -> Package Settings ->Alignment 若是沒有最後的"Alignment"選項,說明你尚未安裝此插件。編碼

這裏面有5個選項:spa

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

帶有後綴Default的,爲默認設置,每次升級插件都會重置這裏的設置。因此儘可能不要修改這裏,不然升級會丟失你原先的設置。.net

帶有後綴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數組一致。即在全部的對齊字符前面都增長一個空格。

相關文章
相關標籤/搜索