Indentation of files in vim.
We all wish to indent files in vim so that the code looks more uniform and coherent across multiple systems.
Here's a script written to indent file which runs on bash. This script expects an input (argument) from the user which can be file name or a directory path [assumed that user wishes to run the script for all files in that directory]
================================================================
#!/bin/bash
#Pass absolute file name which you wish to indent as an argument to this script
argument=$1
if [[ -d $argument ]]; then
echo "$argument is a directory"
#file=$argument/*
for file in `find $argument -type f -name "*.c" && find $argument -type f -name "*.h"`
do
echo $file
vim $file -c "normal gg=G" -c "wq"
expand -t 4 $file $file
done
elif [[ -f $argument ]]; then
echo "$argument is a file"
file=$argument
vim $file -c "normal gg=G" -c "wq"
expand -t 4 $file $file
else
echo "$argument is not valid"
exit 1
fi
================================================================
Save the above code as indent.sh.
Here's a script written to indent file which runs on bash. This script expects an input (argument) from the user which can be file name or a directory path [assumed that user wishes to run the script for all files in that directory]
================================================================
#!/bin/bash
#Pass absolute file name which you wish to indent as an argument to this script
argument=$1
if [[ -d $argument ]]; then
echo "$argument is a directory"
#file=$argument/*
for file in `find $argument -type f -name "*.c" && find $argument -type f -name "*.h"`
do
echo $file
vim $file -c "normal gg=G" -c "wq"
expand -t 4 $file $file
done
elif [[ -f $argument ]]; then
echo "$argument is a file"
file=$argument
vim $file -c "normal gg=G" -c "wq"
expand -t 4 $file $file
else
echo "$argument is not valid"
exit 1
fi
================================================================
Save the above code as indent.sh.
Type ./indent.sh <filepath/dirpath>.
Comments
Post a Comment