Auto-Indentation of HTML

4 views
Skip to first unread message

Steve Laurie

unread,
Dec 10, 2008, 6:58:34 AM12/10/08
to vim...@googlegroups.com
Hi all,

I've tried to find what's causing this and can't.

Currently, I'm working on an HTML doc and say for example, the cursor is
on a line that has only a </p> tag on it. I position the cursor to the
end of the line and press ENTER to go to the next line to begin the next
paragraph BUT... when I do, the preceding </p> tag indents itself 1 tab
space to the right. If I've got lots of paragraphs to add, eventually,
the width of the paragraphs gets narrower and narrower because they all
want to indent when I press ENTER after them.

How do I stop them from indenting when I press enter to go to the next
new line?

TIA and Regards,
Steve Laurie


Cory Echols

unread,
Dec 10, 2008, 7:18:40 AM12/10/08
to vim...@googlegroups.com

I'm not sure why vim thinks your </p> tag needs to be indented one
more level, but the fact that it does it when you hit ENTER could be
caused by the value of either 'cinkeys' or 'indentkeys'. If either of
those options have an "o" in them, vim indents the current line when
you hit ENTER.

Yongwei Wu

unread,
Dec 10, 2008, 7:52:55 AM12/10/08
to vim...@googlegroups.com
2008/12/10 Steve Laurie <badm...@foo-unix.org>:

My solution may be a hack, but it works. I put this in my _vimrc:

au FileType html,xhtml setlocal indentexpr=

Best regards,

Yongwei

--
Wu Yongwei
URL: http://wyw.dcweb.cn/

David Fishburn

unread,
Dec 10, 2008, 9:26:49 AM12/10/08
to vim...@googlegroups.com
On 12/10/08, Steve Laurie <badm...@foo-unix.org> wrote:
>
> Hi all,
>
> I've tried to find what's causing this and can't.
>
> Currently, I'm working on an HTML doc and say for example, the cursor is
> on a line that has only a </p> tag on it. I position the cursor to the
> end of the line and press ENTER to go to the next line to begin the next
> paragraph BUT... when I do, the preceding </p> tag indents itself 1 tab
> space to the right.

Can you show us the simple HTML that demonstrates this.
Just to be sure, you didn't want to use <p/> instead right?

The indent/html.vim file is designed to be customizable.
You can control which tags should be indented and which shouldn't.

This is done via your .vimrc.

Dave

Steve Laurie

unread,
Dec 10, 2008, 9:48:27 AM12/10/08
to vim...@googlegroups.com
It's not entered as <p/>. Apart from the fact that I put my tags in by
keymappings, it happens with other tags as well. I just used <p></p> as
an example.

Here's an example of what I was saying:

<p>Although the crontab file looks like an ordinary file, it's not
and if you try to edit it directly, you'll screw it up.
To add/modify/delete anything from your crontab, use the
following command:
</p>


When I press enter after the last </p> to get to the new line below it,
the above paragraph looks like:

<p>Although the crontab file looks like an ordinary file, it's not
and if you try to edit it directly, you'll screw it up.
To add/modify/delete anything from your crontab, use the
following command:
</p>
<p>


and my new paragraph starts below the </p>. Eventually, it all works
itself over to the right hand side of the document.

Cheers,
Steve

Steve Laurie

unread,
Dec 10, 2008, 9:58:35 AM12/10/08
to vim...@googlegroups.com
Ah Thank You very much Cory,

It's got to do with indentkeys. I set :indentkeys="" and it stopped
happening.

What would be the best value for this setting given that I'm working on
X/HTML files. (I'll put it in my ~/.vim/after/ftplugin/html.vim file).

Ta,
Steve

Steve Laurie

unread,
Dec 10, 2008, 10:18:57 AM12/10/08
to vim...@googlegroups.com
I'm trying to set indentkeys in my ~/.vimrc file and I've also tried to
set it in my ~/.vim/after/ftplugin/html.vim file but every time I open
an HTML file, it reverts back to indentkeys=o,O,*<Return>,<>>,{,}

I've even copied and pasted it from the :set listing.

How do I get it to stay set?

Thanks,
Steve

Steve Laurie

unread,
Dec 10, 2008, 10:36:12 AM12/10/08
to vim...@googlegroups.com
Thanks Cory/everyone,

I got it. It was the fact that I had

filetype plugin indent on

in my ~/.vimrc file set. When I took out the indent from that line, it
allowed me to set indentkeys in my ~/.vim/after/ftplugin/html.vim file.

Have a good day/night all,

Regards,
Steve


fritzophrenic

unread,
Dec 10, 2008, 1:09:46 PM12/10/08
to vim_use
I think that 'autoindent', 'smartindent', and 'cindent' can all
interfere with filetype indent rules.

You should probably check the values of all these options.

I personally have zero problems with the html indent behavior, which
actually works very well on my setup.
Reply all
Reply to author
Forward
0 new messages