T
With regard to the first part, I regret to say nothing (in principle, I believe that such a function has been redundant) but I'll sue for the second part.There's a torso to check and format. html: tidy♪ Plagina vim I don't know for her, but this shoe is beautifullyting. vim:First we add a backup function to copy. diff current buffer (copulation of all output You can't, because in that case you're having trouble rolling back.function! CopyDiffToBuffer(input, output, bufname)
" prevent out of range in cickle
let min_len=min([len(a:input), len(a:output)])
" copy all lines, that was changed
for i in range(0, min_len - 1)
let output_line=a:output[i]
let input_line=a:input[i]
if input_line != output_line
call setline(i + 1, output_line) " lines calculate from 1, items - from 0
end
endfor
" in this case we have to handle all lines, that was in range
if len(a:input) != len(a:output)
if min_len == len(a:output) " remove all extra lines from input
call deletebufline(a:bufname, min_len + 1, "$")
else " append all extra lines from output
call append("$", a:output[min_len:])
end
end
endfunction
The formatting function is:function! HTMLFormat()
let input=getline(1, "$")
let error_file=tempname()
let output_str=system("tidy -qi -ashtml 2>" . error_file, input)
if len(output_str) " all right
let output=split(output_str, "\n")
call CopyDiffToBuffer(input, output, bufname("%"))
" alse cleare lbuffer
lexpr ""
lwindow
else " we got error
let errors=readfile(error_file)
let source_file=bufname("%")
call insert(errors, source_file) " append filename for right errorformat
set efm=%+P%f,line\ %l\ column\ %c\ -\ %t%*[^:]:\ %m,%-Q
lexpr errors
lwindow 5
end
call delete(error_file)
endfunction
Failure verification functionfunction! HTMLCheck()
let input=getline(1, '$')
let errors=system('tidy -q -e', input)
if len(errors) " ther are some errors
" append filename for right errorformat
let source_file=bufname("%")
let errors=source_file . "\n" . errors
set efm=%+P%f,line\ %l\ column\ %c\ -\ %t%*[^:]:\ %m,%-Q
lexpr errors
lwindow 5
else " no errors, so we must clear lbuffer
lexpr ""
lwindow
endif
endfunction
Add the taste combinations for testing and formatting, as well as the automatic formats when the file is closed:autocmd FileType html nnoremap <buffer> <c-k> :call HTMLFormat()<cr>
autocmd BufWrite *.html call HTMLFormat()
autocmd FileType html nnoremap <buffer> <c-f> :call HTMLCheck()<cr>
Enough. tidy and add this code .vimrc and yours. vim built-in tunnels for formatting and validation HTML