m (remove nice but unhelpful comments) |
Tag: Visual edit |
||
(One intermediate revision by one other user not shown) | |||
Line 3: | Line 3: | ||
|previous=1206 |
|previous=1206 |
||
|next=1215 |
|next=1215 |
||
− | |created= |
+ | |created=2006 |
|complexity=advanced |
|complexity=advanced |
||
|author=[[User:Heptite|Heptite]] |
|author=[[User:Heptite|Heptite]] |
||
Line 12: | Line 12: | ||
|category3=PHP |
|category3=PHP |
||
}} |
}} |
||
− | This script allows you to indent HTML sections in PHP files. Create file < |
+ | This script allows you to indent HTML sections in PHP files. Create file <code>~/.vim/indent/php.vim</code> (<code>$HOME/vimfiles/indent/php.vim</code> on Windows systems) containing the following: |
<pre> |
<pre> |
||
Line 20: | Line 20: | ||
finish |
finish |
||
endif |
endif |
||
− | |||
" This script pulls in the default indent/php.vim with the :runtime command |
" This script pulls in the default indent/php.vim with the :runtime command |
||
" which could re-run this script recursively unless we catch that: |
" which could re-run this script recursively unless we catch that: |
||
Line 31: | Line 30: | ||
runtime! indent/php.vim |
runtime! indent/php.vim |
||
unlet s:doing_indent_inits |
unlet s:doing_indent_inits |
||
− | |||
function! GetPhpHtmlIndent(lnum) |
function! GetPhpHtmlIndent(lnum) |
||
if exists('*HtmlIndent') |
if exists('*HtmlIndent') |
||
Line 52: | Line 50: | ||
return -1 |
return -1 |
||
endfunction |
endfunction |
||
− | |||
setlocal indentexpr=GetPhpHtmlIndent(v:lnum) |
setlocal indentexpr=GetPhpHtmlIndent(v:lnum) |
||
setlocal indentkeys+=<>> |
setlocal indentkeys+=<>> |
||
Line 59: | Line 56: | ||
==Comments== |
==Comments== |
||
I personally think it's more straightforward to just :set ft=html while you're editing HTML blocks. |
I personally think it's more straightforward to just :set ft=html while you're editing HTML blocks. |
||
+ | |||
+ | This plugin works for entering new text, but not for using = on a selection, right? Any chance there's a way to fix that as well in the same thing? |
Revision as of 14:18, 21 May 2014
Tip 1213 Printable Monobook Previous Next
created 2006 · complexity advanced · author Heptite · version 5.7
This script allows you to indent HTML sections in PHP files. Create file ~/.vim/indent/php.vim
($HOME/vimfiles/indent/php.vim
on Windows systems) containing the following:
" 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+=<>>
Comments
I personally think it's more straightforward to just :set ft=html while you're editing HTML blocks.
This plugin works for entering new text, but not for using = on a selection, right? Any chance there's a way to fix that as well in the same thing?