Tip 1213 Printable Monobook Previous Next
created April 22, 2006 · complexity advanced · author Anon · version 5.7
1) Append the indent/html.vim to indent/php.vim (from if exists('g:html_indent_tags'), and everything below)
2) Create a function in indent/php.vim
function! GetPhpHtmlIndent(lnum) let html_ind = HtmlIndentGet(a:lnum) let php_ind = GetPhpIndent() " priority one for php indent script if php_ind > -1 return php_ind endif if html_ind > -1 return html_ind endif return -1 endfunction
3) Put setlocal indentexpr=GetPhpHtmlIndent(v:lnum) indentkeys+=<>> in indent/php.vim
4) Search for ' [-- special handling for <pre>: no indenting --]' in indent/html.vim and append the following:
" [-- special handling for <pre>: no indenting --] if getline(a:num) =~ "^<?" && (0< searchpair('<?', '', '?>', 'nWb') \ || 0 < searchpair('<?', '', '?>', 'nW')) return -1 endif
Comments
A version that doesn't touch the global runtime files. Create ~/.vim/indent/php.vim and put the following in it:
" Better indent support for PHP by making it possible to indent HTML sections " as well. if exists("b:did_indent") finish endif " This script pulls in the default indent/php.vim with the :runtime command " which could re-run this script recursively unless we catch that: if exists('s:doing_indent_inits') finish endif let s:doing_indent_inits = 1 runtime! indent/html.vim unlet b:did_indent runtime! indent/php.vim unlet s:doing_indent_inits function! GetPhpHtmlIndent(lnum) if exists('*HtmlIndent') let html_ind = HtmlIndent() else let html_ind = HtmlIndentGet(a:lnum) endif let php_ind = GetPhpIndent() " priority one for php indent script if php_ind > -1 return php_ind endif if html_ind > -1 if getline(a:num) =~ "^<?" && (0< searchpair('<?', '', '?>', 'nWb') \ || 0 < searchpair('<?', '', '?>', 'nW')) return -1 endif return html_ind endif return -1 endfunction setlocal indentexpr=GetPhpHtmlIndent(v:lnum) setlocal indentkeys+=<>>
-- Heptite (T) (C) (@) 09:14, 3 March 2008 (UTC)