You are not logged in.

#1 2007-05-04 12:38:46

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Vim XHTML indentation

Is there some config line I need to get decent auto indentation in (x)html files in Vim?

Atm there is no auto-indentation whatsoever while typing, and 'gg=G' does absolutely nothing (which is expected from the first fact, I realise =P).

Cheers.

- KD

Offline

#2 2007-05-04 13:26:18

chicha
Member
From: France
Registered: 2007-04-20
Posts: 271

Re: Vim XHTML indentation

Try this in your .vimrc :

set autoindent                          
set smartindent
set shiftwidth=4

If it is not already the case ....
Cheers,
Chicha

Offline

#3 2007-05-04 13:34:54

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: Vim XHTML indentation

chicha wrote:

Try this in your .vimrc :

set autoindent                          
set smartindent
set shiftwidth=4

If it is not already the case ....
Cheers,
Chicha

Thanks for the response, Chicha. Sadly I already have those.

For anyone responding, my .vimrc can be seen in this thread.

- KD

Offline

#4 2007-05-04 14:00:15

chicha
Member
From: France
Registered: 2007-04-20
Posts: 271

Re: Vim XHTML indentation

Arff ...
I have no idea then, sorry sad
Did you try vim.org for a script/tips ? we never know ...

Offline

#5 2007-05-04 14:01:31

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: Vim XHTML indentation

chicha wrote:

Arff ...
I have no idea then, sorry sad
Did you try vim.org for a script/tips ? we never know ...

Yeah, I looked but found nothing relevant sad I searched for 'html', 'xhtml', 'indent', and 'format', and nothing useful came up.
- KD

Last edited by KomodoDave (2007-05-04 14:01:46)

Offline

#6 2007-05-04 14:06:45

chicha
Member
From: France
Registered: 2007-04-20
Posts: 271

Re: Vim XHTML indentation

I did too and same result, unfortunatly ...
Can you post a sample xhtml file which cause indentation problems in your vim (if it is not condidential of course wink ) so that I try with my vim and see if it is a config problem or a vim problem ?

Offline

#7 2007-05-04 20:13:18

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Vim XHTML indentation

Hmmmm xhtml indentation works for me. I'm not sure what I'm doing differently.

Offline

#8 2007-05-04 23:47:38

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: Vim XHTML indentation

phrakture wrote:

Hmmmm xhtml indentation works for me. I'm not sure what I'm doing differently.

I feel enlightened *cough* =P  I haven't changed much from your .vimrc; i've only added stuff, and nothing that directly relates to indentation, afaik. Grr...

- KD

Offline

#9 2007-05-04 23:57:44

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: Vim XHTML indentation

chicha wrote:

I did too and same result, unfortunatly ...
Can you post a sample xhtml file which cause indentation problems in your vim (if it is not condidential of course wink ) so that I try with my vim and see if it is a config problem or a vim problem ?

et voila:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta name="keywords" content="komodo dave, komododave, kd blog, kdblog"/>
<meta name="description" content="Articles and blog by KomodoDave" />
<meta name="revised" content="N David Brown, 29/04/2007" />
<meta name="refresh" content="5" />
<title></title>
<link rel="stylesheet" type="text/css" href="stylesheets/main.css" />
<script src="javascript/head_script.js"></script>
</head>
<body>
<div id="title_links">
<img class="title_links" name="title_link" id="title_links_about" src="images/title_links_about.png"/>
<img class="title_links" name="title_link" id="title_links_articles" src="images/title_links_articles.png"/>
<img class="title_links" name="title_link" id="title_links_blog" src="images/title_links_blog.png"/>
</div>
<img id="title_kd" src="images/title_kd.png"/>
<img id="title_bars" src="images/title_bars.png"/>
</body>
</html>

Last edited by KomodoDave (2007-05-04 23:58:01)

Offline

#10 2007-05-05 00:26:44

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Offline

#11 2007-05-05 00:30:24

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: Vim XHTML indentation

I guess it must be something in my .vimrc then (linked above) O_o  I'll scour it and see what comes up.

Cheers for posting, phrak.

- KD

Offline

#12 2007-05-05 00:33:33

nj
Member
Registered: 2007-04-06
Posts: 93

Re: Vim XHTML indentation

Start vim with the -V option to see if any indent type files are sourced.

In your vimrc you set the filetype of *.html files to htmlm4. This shouldn't be what is causing the problem, but you might try commenting that line out just to be sure.

Offline

#13 2007-05-05 00:38:00

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: Vim XHTML indentation

nj wrote:

Start vim with the -V option to see if any indent type files are sourced.

In your vimrc you set the filetype of *.html files to htmlm4. This shouldn't be what is causing the problem, but you might try commenting that line out just to be sure.

Here's vim -V myfile | grep sourcing

 sourcing "/usr/share/vim/syntax/php.vim"                                                    
line 86: sourcing "/usr/share/vim/syntax/html.vim"                                                                                          
line 165: sourcing "/usr/share/vim/syntax/javascript.vim"                                                                                   
finished sourcing /usr/share/vim/syntax/javascript.vim                                                                                      
line 190: sourcing "/usr/share/vim/syntax/vb.vim"                                                                                           
finished sourcing /usr/share/vim/syntax/vb.vim                                                                                              
line 200: sourcing "/usr/share/vim/syntax/css.vim"                                                                                          
finished sourcing /usr/share/vim/syntax/css.vim                                                                                             
finished sourcing /usr/share/vim/syntax/html.vim                                                                                            
line 109: sourcing "/usr/share/vim/syntax/sql.vim"                                                                                          
line 37: sourcing "/usr/share/vim/syntax/sqloracle.vim"                                                                                     
finished sourcing /usr/share/vim/syntax/sqloracle.vim                                                                                       
finished sourcing /usr/share/vim/syntax/sql.vim                                                                                             
finished sourcing /usr/share/vim/syntax/php.vim                                                                                             
line 17: sourcing "/usr/share/vim/ftplugin/php.vim"                                                                                         
line 20: sourcing "/usr/share/vim/ftplugin/html.vim"                                                                                        
finished sourcing /usr/share/vim/ftplugin/html.vim                                                                                          
finished sourcing /usr/share/vim/ftplugin/php.vim

It uses /usr/share/vim/syntax/html.vim and ..../ftplugin/html.vim, by the looks of it.

I tried commenting out that line, thank you nj, but it sadly made no difference.

- KD

Offline

#14 2007-05-05 01:12:41

nj
Member
Registered: 2007-04-06
Posts: 93

Re: Vim XHTML indentation

Run ':set ft?' in vim to make sure the filetype is not set to php. If it is php, you can run ':verbose set ft?' to see where the filetype was last set.

Do you have anything in your ~/.vim/{after,ftdetect,ftplugin} folders? Try renaming your .vim folder to make sure no plugins are the problem.

Offline

#15 2007-05-05 01:16:55

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: Vim XHTML indentation

nj wrote:

Run ':set ft?' in vim to make sure the filetype is not set to php. If it is php, you can run ':verbose set ft?' to see where the filetype was last set.

Do you have anything in your ~/.vim/{after,ftdetect,ftplugin} folders? Try renaming your .vim folder to make sure no plugins are the problem.

Clearly you know your vim commands smile ':set ft?' gave me 'php', and the ':verbose' command gave me

filetype=php
    Last set from /usr/share/vim/filetype.vim

I've tried renaming each of my folders in ~/.vim/ sequentially, testing whether any plugins are causing the problem. They don't seem to be though.

Is it possible some plugin I installed at one point in the past overwrote /usr/share/vim/filetype.vim, and that's what's causing the problem? I'll try reinstalling vim now and get back to you.

Edit: Nope, still no joy >_<  I tried reinstalling vim, having removed it first, and everything's still the same

- KD

Last edited by KomodoDave (2007-05-05 01:28:05)

Offline

#16 2007-05-05 01:35:35

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: Vim XHTML indentation

I'm such an idiot. I was trying to indent in my file 'index.php', which of course is going to produce a filetype of php, lol. Is .phtml a php/html hybrid? Is there a syntax file for html and php combined?

Sorry, and thanks a lot for your advice; that ':set ft?' is a useful tidbit to remember, nj.

- KD

Offline

#17 2007-05-05 01:51:37

nj
Member
Registered: 2007-04-06
Posts: 93

Re: Vim XHTML indentation

Looking at filetype.vim, the only reason it sets the filetype to php is due to the filename being *.php or *.php[0-9]. Is this the case for your file?

If not, then you can use an autocmd similar to that htmlm4 line to change the filetype to xhtml.

Edit:
Beaten to the answer smile

I've never done much with php, so I'm not sure how dual html/php indenting works. There is a phtml type, but from a quick test it doesn't seem to indent the html at all.

By the way, the ? in the :set command tells you the current state of a variable and is not specific to just the filetype. So you can use, for instance, :set tabstop? to see what the tabstop is.

Happy vimming smile

Last edited by nj (2007-05-05 02:00:19)

Offline

#18 2007-05-05 01:55:05

KomodoDave
Member
From: Oxford, UK
Registered: 2007-04-22
Posts: 162
Website

Re: Vim XHTML indentation

^^ yeah, it's .php, lol. Oops =S

I'll put in an autocmd to use the html syntax file for .php files.

Thanks for all your help; it's very much appreciated.

- KD

Offline

Board footer

Powered by FluxBB