dhruvasagar / vim-table-mode

VIM Table Mode for instant table creation.
2.11k stars 96 forks source link

Table Cell Length Is NOT Displayed Correctly for Multi-byte #28

Closed zcchen closed 10 years ago

zcchen commented 10 years ago

Hi,

I am not sure whether it is a bug or just a feature request.

If the contents in table cells are contained multi-byte, like CJK characters, the length of table cell may be not correct. eg.

+----------------+-------+
| some eng words | 来几个汉字 |
+----------------+------------+
| good           | bad        |
+----------------+------------+

Notice the function named "GenerateHeaderBorder" in file "autoload/tablemode/table.vim". It seems just replacing some chars to g:table_mode_fillchar and similar chars to make the table bar. For a Latin letter, it is always showed in ONE byte, but the CJK character needs TWO bytes.

Therefore, I suggested to add some codes to support this feature or fix this bug. Is it difficult to support ?

Thank you very much.

FYI, if you want to use reqular expressions to select CJK characters, you could use this /[^\x00-\xff]

dhruvasagar commented 10 years ago

Hi, as far as the border goes, I agree, I hadn't thought of this before and i'll fix the issue, it shouldn't be too difficult.

However as far as alignment goes, the tables should align perfectly well (leave aside the borders) with double byte characters such as the ones displayed in your text. Kindly check and let me know regarding the same.

zcchen commented 10 years ago
+--------------+--------------+---------+
| abc          | 测试长度         | 长测试     |
+--------------+--------------+---------+
| 长           | 测试测试测试测试 | 测试测试   |
+----------+----------------+-------+
| 测试测试     | 测试             | 测试测测试 |
+----------+----------------+-------+
| 测试测试测试 | 测试测试         | 测试       |
+--------+--------------+----------+

I don't know why, the length for top/bottom/middle bars are all different. :-(

zcchen commented 10 years ago

By the way, if you want to generate some Chinese characters to Vim, you could just install one Chinese IME, like google-pinyin (Windows), ibus-pinyin (Linux).

Thank you very much.

dhruvasagar commented 10 years ago

Kindly update the plugin and try it out, for me it works as expected.

zcchen commented 10 years ago

I have tested it today. It works well as I expected.

Thank you very much.

dhruvasagar commented 10 years ago

Great!