Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
command! -range=0 PhpTidy call s:php_tidy(<count>, <line1>, <line2>)
function! s:php_tidy(has_range, line1, line2)
if !exists('g:php_tidy_tmp')
let g:php_tidy_tmp = '/path/to/php_tidy'
if !exists('g:php_tidy_cmd')
let g:php_tidy_cmd = '/path/to/tools/ '
if a:has_range
call writefile(getline(a:line1, a:line2), g:php_tidy_tmp)
let l:res = system(g:php_tidy_cmd . g:php_tidy_tmp)
let l:res = substitute(l:res, '<?php\s*', '', "")
let l:res = substitute(l:res, '\s*?>$', '', "")
let l:lines = split(l:res, "\n")
" call delete(tmp)
execute ':silent ' . a:line1 . ',' . a:line2 . 'delete'
call append(a:line1 - 1, l:lines)
let l:cnt = len(l:lines) - 1
execute ':normal! kV' . (l:cnt) .'k'
execute ':normal! ='
execute ':normal mx'
execute ':%:!' . g:php_tidy_cmd . '%'
execute ':normal `x'
execute ':delmarks x'
php=`which php`
$php $stylist "$@" \
--indent_size 4 \
--line_before_comment_multi \
--keep_redundant_lines \
--space_after_comma \
--space_around_assignment \
--align_var_assignment \
--space_around_comparison \
--space_around_arithmetic \
--space_around_logical \
--space_around_colon_question \
--line_before_function \
--space_after_if \
--add_missing_braces \
--space_inside_for \
--indent_case \
--line_after_break \
--space_around_double_arrow \
--space_around_concat \
--vertical_array \

This comment has been minimized.

Copy link

zeroasterisk commented Aug 2, 2012

this looks exactly like what I've been looking for -- can you provide a bit more documentation or "how to install" for me, i'm newish to vim and uncertain how to implement... thought about releasing as a bundle?


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.