vim plugin Tablify (表格转化插件)

Tablify is a VIM plugin that turns simple structured data into nice-looking tables.

Installation

Put tablify.vim in your vim's plugin directory and you're ready to go.
For pathogen users, just:

cd ~/.vim/bundle
git clone git://github.com/Stormherz/tablify.git

And you're ready to go.

Usage

There is a small list of commands you need to know before starting making tables out of your text. Assuming your <Leader> is \:
\tl or \tt - turns selected lines into table (left-aligned text)
\tc - turns selected lines into table (centered text)
\tr - turns selected lines into table (right-aligned text)
\tu - convert selected table back into raw text format in case you want to add some changes in it

\ta - select formed table with cursor anywhere inside of it (also selects structured text for future tables)

Operations with formed and selected table:
\ts - sort table (column number will be prompted), supports text and numeric sorting

Every line of your future table is a text line with cells, separated by | symbol (or any other symbol you choose forg:tablify_raw_delimiter variable in your .vimrc file).

Let's assume we have a few lines of text we would like to see as table:

Artist | Song | Album | Year
Tool | Useful idiot | Ænima | 1996
Pantera | Cemetery Gates | Cowboys from Hell | 1990
Ozzy Osbourne | Let Me Hear You Scream | Scream | 2010

Now select these lines and press \tt to make a table:

+---------------+------------------------+-------------------+------+
| Artist        | Song                   | Album             | Year |
+---------------+------------------------+-------------------+------+
| Tool          | Useful idiot           | Ænima             | 1996 |
+---------------+------------------------+-------------------+------+
| Pantera       | Cemetery Gates         | Cowboys from Hell | 1990 |
+---------------+------------------------+-------------------+------+
| Ozzy Osbourne | Let Me Hear You Scream | Scream            | 2010 |
+---------------+------------------------+-------------------+------+

I bet it was pretty simple. Now you can press u to undo making of table or select table and press \tu to return to the text you're started from. After that you can try \tc and \tr to see what it looks like to have aligned text in table.

It is obvious that our table here have some kind of header and it will be great to visually distinguish it from table data. To do so, just separate the header cells with # symbol (or any other symbol you choose for g:tablify_header_delimiter variable in your.vimrc file):

Artist # Song # Album # Year
Tool | Useful idiot | Ænima | 1996
Pantera | Cemetery Gates | Cowboys from Hell | 1990
Ozzy Osbourne | Let Me Hear You Scream | Scream | 2010

And that's what we get after tablification:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Artist        | Song                   | Album             | Year |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Tool          | Useful idiot           | Ænima             | 1996 |
+---------------+------------------------+-------------------+------+
| Pantera       | Cemetery Gates         | Cowboys from Hell | 1990 |
+---------------+------------------------+-------------------+------+
| Ozzy Osbourne | Let Me Hear You Scream | Scream            | 2010 |
+---------------+------------------------+-------------------+------+

There is no problem of making tables out of commonly prefixed text lines, like:

/**
 * Artist#Song#Album#Year
 * Tool|Useful idiot|Ænima|1996
 * Pantera|Cemetery Gates|Cowboys from Hell|1990
 * Ozzy Osbourne|Let Me Hear You Scream|Scream|2010
 *
 */

Multiline cell content is also supported, just place \n where line break should occur, and tablify will do the rest:

Artist # Song # Album # Year
Pantera | Cemetery Gates | Cowboys from Hell | 1990
Tool \n (great perfomance)| Useful idiot | Ænima | 1996
Ozzy Osbourne | Let Me Hear You \n Scream | Scream | 2010

The sample above transforms to table:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Artist             | Song            | Album             | Year |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Pantera            | Cemetery Gates  | Cowboys from Hell | 1990 |
+--------------------+-----------------+-------------------+------+
| Tool               | Useful idiot    | Ænima             | 1996 |
| (great perfomance) |                 |                   |      |
+--------------------+-----------------+-------------------+------+
| Ozzy Osbourne      | Let Me Hear You | Scream            | 2010 |
|                    | Scream          |                   |      |
+--------------------+-----------------+-------------------+------+

Configuration

Tablify behaviour can be configured on per-buffer basis with the folowing variables:
g:loaded_tablify - set to 1 to disable loading of the plugin
b:tablify_headerDelimiter - default value is #, symbol that separates header cells in text
b:tablify_delimiter - default value is |, symbol that separated value cells in text

b:tablify_vertDelimiter - default value is |, vertical delimiter symbol for filling up table rows
b:tablify_horDelimiter - default value is -, horizontal delimiter symbol for filling up table rows
b:tablify_horHeaderDelimiter - default value is ~, horizontal delimiter symbol for filling up tabls header rows
b:tablify_divideDelimiter - default value is +, symbol at the row/column intersection

b:tablify_cellLeftPadding - default value is 1, number of spaces used for left cell padding
b:tablify_cellRightPadding - default value is 1, number of spaces used for right cell padding

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值