How to indent php+html+javascript code using Vim on Linux

1. install full vim with plugins.
put following vim commands in /root/.vimrc

:set nocompatible
:filetype indent on
:syntax on
:set tabstop=4
:set shiftwidth=4
:set expandtab

2. create a vim script file (lets say vimscript.scr) in /root
put the following vim commands in vimscript.scr file

" this is a vim script comment
" remove \r in case file is from windows world

" set filetype as javascript and indent it
:set ft=javascript

" set filetype as html and indent it
:set ft=html

" set filetype as php and indent it
:set ft=php

" convert multiple blank lines to single blank line

" after indenting save file
" script end

3. to indent all php files in a dir, go to that dir and run
#find . -type f -name '*.php' -exec vim -s /root/vimscript.scr "{}" \;

No comments: