|
25 | 25 | if !exists("g:pangu_rule_trailing_whitespace") |
26 | 26 | let g:pangu_rule_trailing_whitespace=1 |
27 | 27 | endif |
| 28 | +if !exists("g:pangu_rule_date") |
| 29 | + let g:pangu_rule_date = 2 |
| 30 | +endif |
28 | 31 |
|
29 | 32 | function! PanGuSpacingCore(mode) range |
30 | 33 | let ignore = search("PANGU_DISABLE", 'n') |
@@ -110,6 +113,32 @@ function! PanGuSpacingCore(mode) range |
110 | 113 | silent! execute firstline . ',' . lastline . 's/\([a-zA-Z0-9!&;=\]\,\.\:\?\$\%\^\-\+\)\\]\)\([\u4e00-\u9fa5\u3040-\u30FF]\)/\1 \2/g' |
111 | 114 | endif |
112 | 115 |
|
| 116 | + " 默认日期每个数字都留白,向前兼容。 |
| 117 | + " 例: |
| 118 | + " 在 2017 年 8 月 7 日生日。 |
| 119 | + " 在2017年8月7日。 |
| 120 | + if g:pangu_rule_date == 0 |
| 121 | + " 日期两端也不留白 |
| 122 | + " 例: |
| 123 | + " 我在2017年8月7日生日。 |
| 124 | + " 在2017年8月7日。 |
| 125 | + silent! execute firstline . ',' . lastline . 's/\s*\(\d\{4,5}\)\s*年\s*\(\d\{1,2}\)\s*月/\1年\2月/g' |
| 126 | + silent! execute firstline . ',' . lastline . 's/\s*\(\d\{1,2}\)\s*月\s*\(\d\{1,2}\)\s*日/\1月\2日/g' |
| 127 | + silent! execute firstline . ',' . lastline . 's/\s*\(\d\{4,5}\)\s*年\s*\(\d\{1,2}\)\s*月\s*\(\d\{1,2}\)\s*日/\1年\2月\3日/g' |
| 128 | + " 去除两端留白 |
| 129 | + silent! execute firstline . ',' . lastline . 's/\(\(\d\{4,5}年\)\?\d\{1,2}月\(\d\{1,2}日\)\?\)\s\+\([\u4e00-\u9fa5\u3040-\u30FF]\)/\1\4/g' |
| 130 | + elseif g:pangu_rule_date == 1 |
| 131 | + " 日期两端留白 |
| 132 | + " 例: |
| 133 | + " 我在 2019年12月1日 生日。 |
| 134 | + " 在 2017年8月7日。 |
| 135 | + silent! execute firstline . ',' . lastline . 's/\(\d\{4,5}\)\s*年\s*\(\d\{1,2}\)\s*月/\1年\2月/g' |
| 136 | + silent! execute firstline . ',' . lastline . 's/\(\d\{1,2}\)\s*月\s*\(\d\{1,2}\)\s\+日/\1月\2日/g' |
| 137 | + silent! execute firstline . ',' . lastline . 's/\(\d\{4,5}\)\s*年\s*\(\d\{1,2}\)\s*月\s*\(\d\{1,2}\)\s\+日/\1年\2月\3日/g' |
| 138 | + " 两端留白 |
| 139 | + silent! execute firstline . ',' . lastline . 's/\(\(\d\{4,5}年\)\?\d\{1,2}月\(\d\{1,2}日\)\?\)\([\u4e00-\u9fa5\u3040-\u30FF]\)/\1 \4/g' |
| 140 | + endif |
| 141 | + |
113 | 142 | if g:pangu_rule_trailing_whitespace == 1 |
114 | 143 | silent! execute firstline . ',' . lastline . 's/^ \[/[/' |
115 | 144 | silent! execute firstline . ',' . lastline . 's/\s\+$//' |
|
0 commit comments