vim下php文件中自动缩排html代码
生活随笔
收集整理的這篇文章主要介紹了
vim下php文件中自动缩排html代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題:vim下怎樣在php文件中通過 = 命令自動縮排html代碼?解決:1、先說下html自動縮排
我的vim是7.4版本,已經包含了html.vim之類的縮排插件,但是縮排的時候<body> <head> 沒有進行縮排
在.vimrc中加入如下代碼即可對 <body> <head> 也進行縮排" html indent
filetype indent on
let g:html_indent_inctags = "body,head,tbody" " 縮進body head
" let g:html_indent_script1 = "inc" " 縮進<script>標簽
" let g:html_indent_style1 = "inc" " 縮進<style>標簽2、解決php文件中html代碼縮進創建 ~/.vim/indent/php.vim 文件,如果沒有indent目錄,就先創建indent目錄
然后在 php.vim 文件中粘貼如下代碼并保存" 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()elselet html_ind = HtmlIndentGet(a:lnum)endiflet php_ind = GetPhpIndent()" priority one for php indent scriptif php_ind > -1return php_indendifif html_ind > -1if getline(a:num) =~ "^<?" && (0< searchpair('<?', '', '?>', 'nWb')\ || 0 < searchpair('<?', '', '?>', 'nW'))return -1endifreturn html_indendifreturn -1
endfunction
setlocal indentexpr=GetPhpHtmlIndent(v:lnum)
setlocal indentkeys+=<>>3、在 .vimrc 中還需要添加 filetype indent on 打開根據文件類型自動縮進
在vim命令模式下中輸入 gg=G 即可完成自動縮排參考:
http://www.vim.org/scripts/script.php?script_id=2075
http://blog.longwin.com.tw/2009/01/vim-indent-for-php-html-2009/
http://cache.baiducontent.com/c?m=9d78d513d9871af04fede53c5754c066680ec63c62c0d0642488c51fcf224f060738ece161645213d2b6617a45f4164bea8773296e5873a09bbfd91782a6d77376d33a44275ac01652c41edb901a73967cd64deedb58a0f8b26fd3e8c5d4ab000e8a44020ec2aac94d07608f34b64e26e4d2c30e4a01&p=c06ccc04969d12a05abd9b7e0b1791&newp=9370c64ad48703fa08e294780c4dcf231610db2151d6d7143b96c6&user=baidu&fm=sc&query=vim+php+html+indent&qid=a72951080000046d&p1=2
轉載于:https://www.cnblogs.com/zcube/p/4222410.html
總結
以上是生活随笔為你收集整理的vim下php文件中自动缩排html代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: kafka内存不断增加_为什么 Kafk
- 下一篇: Oracle WorkFlow(工作流)