Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vim reformat html in a strange way

25 views
Skip to first unread message

Zhang Weiwu

unread,
Dec 4, 2009, 8:58:28 AM12/4/09
to
Hello. I am new to using vim author html using debian lenny with only 3
packages installed: vim-runtime, vim-common and vim.

I wrote a HTML file with following segment, the writing process is often
interrupted because when I press 'enter' vim often want to re-indent the
last line, even though 'fo' does not contain 'a' nor 'c'. anyway I
managed to manually indent it like the following:

[snap]
<table>
<tbody>
<tr> <th>时间</th>
<td>11月4日水床加热器送到并安装上,4日夜里出事。
水床系淘宝网上从厂商
<a href="http://shop33219371.taobao.com/shop/xshop/wui_page-cat-33219371-29232759-wMvC/suutLI=.htm?checkedRange=true">艾妮时尚</a>
直接购得。</td>
</tr>
<tr> <th>本站缘起</th>
<td>笔者遇到的情况俾从网民周知,希望能避免大家遇到意外。</td></tr>
<tr> <th>厂商处理办法</th>
<td>要求寄回产品,回复如下</td>
</tr>
</tbody>
</table>
[/snap]


And I do 'gq' to the above segment, vim re-arrange it in a strange way,
copied below:

[snap]
<table> <tbody> <tr> <th>时间</th>
<td>11月4日水床加热器送到并安装上,4日夜里出事。
水床系淘宝网上从厂商 <a
href="http://shop33219371.taobao.com/shop/xshop/wui_page-cat-33219371-29232759-wMvC/suutLI=.htm?checkedRange=true">>艾妮时尚</a>
直接购得。</td> </tr> <tr>
<th>本站缘起</th>
<td>笔者遇到的情况俾从网民周知,希望能避免大家遇到意外。</td></tr>
<tr> <th>厂商处理办法</th> <td>要求寄回产品,回复如下</td>
</tr> </tbody> </table>
[/snap]


The way the text is re-arranged is totally unreasonable to me. e.g.
indents of table cells are too big, the '<tr>' of each table row do not
start from the same text column (so it is not easy from a glance to tell
number of table rows). Is it something wrong on my installation, or is
it really the way many other HTML author prefer to have in vim? In
latter case, what is the logic in this?

Thanks in advance. It is difficult to google useful information because
'html' as a search keyword usually matches the 'html' trailing of URIs
but not page contents.

Cesar Romani

unread,
Dec 4, 2009, 12:56:21 PM12/4/09
to
如下</td>
> </tr> </tbody> </table>
> [/snap]
>
>
> The way the text is re-arranged is totally unreasonable to me. e.g.
> indents of table cells are too big, the '<tr>' of each table row do not
> start from the same text column (so it is not easy from a glance to tell
> number of table rows). Is it something wrong on my installation, or is
> it really the way many other HTML author prefer to have in vim? In
> latter case, what is the logic in this?
>
> Thanks in advance. It is difficult to google useful information because
> 'html' as a search keyword usually matches the 'html' trailing of URIs
> but not page contents.

In normal mode you have to use: gg=G
See help =

Regards

Gary Johnson

unread,
Dec 4, 2009, 4:00:35 PM12/4/09
to
Zhang Weiwu <zhangwe...@realss.com> wrote:
> Hello. I am new to using vim author html using debian lenny with only 3
> packages installed: vim-runtime, vim-common and vim.
>
> I wrote a HTML file with following segment, the writing process is often
> interrupted because when I press 'enter' vim often want to re-indent the
> last line, even though 'fo' does not contain 'a' nor 'c'. anyway I
> managed to manually indent it like the following:

[...]

> And I do 'gq' to the above segment, vim re-arrange it in a strange way,
> copied below:

[...]

> The way the text is re-arranged is totally unreasonable to me. e.g.
> indents of table cells are too big, the '<tr>' of each table row do not
> start from the same text column (so it is not easy from a glance to tell
> number of table rows). Is it something wrong on my installation, or is
> it really the way many other HTML author prefer to have in vim? In
> latter case, what is the logic in this?

Vim makes a distinction between "formatting" and "indenting". When Vim
"formats", it may move text from one line to another in order to fill
and align the selected lines. This is generally not useful for anything
but plain text, e-mail, and some situations in C-like languages. Vim
will not do "prettifying" of source code as it doesn't move tokens among
lines in a language-aware fashion. You've discovered this in your
example above.

When Vim "indents", it adjusts the indentation of lines according to the
rules of the current file type, as specified in the $VIMRUNTIME/indent
files; it does not move any text from one line to another.

So, when editing HTML, Vim can automatically handle indentation for you,
but it's up to you to arrange the lines and tags as you see fit. If
you want a program to do that for you, try Tidy.

In terms of Vim commands, you can use gq to reformat text within a
paragraph, but it won't adjust HTML tags as you'd like. To re-indent
an HTML document, use = instead. See

:help =
:help 30.3

--
Gary Johnson

Zhang Weiwu

unread,
Dec 4, 2009, 9:05:28 PM12/4/09
to
Gary Johnson wrote:
> So, when editing HTML, Vim can automatically handle indentation for you,
> but it's up to you to arrange the lines and tags as you see fit. If
> you want a program to do that for you, try Tidy.
>
> In terms of Vim commands, you can use gq to reformat text within a
> paragraph, but it won't adjust HTML tags as you'd like. To re-indent
> an HTML document, use = instead. See
>
> :help =
> :help 30.3
>
Thank you very much for you detailed explanation. The problem is solved
using = command.
0 new messages