You are not logged in.
I just started learning vim and am wondering how I can get it to auto format some code. For example:
check() {
for i in $nodes; do
ping -c 1 $i > /dev/null
if [ $? -eq 0 ]; then
echo "Looks like $i is up so initializing the cluster on it."
ssh $i "\$HOME/bin/cluster-setup.sh"
fi
done
}
I have tabstop=3 in my ~/.vimrc and I'd just like to apply formatting to that code block so it looks like:
check() {
for i in $nodes; do
ping -c 1 $i > /dev/null
if [ $? -eq 0 ]; then
echo "Looks like $i is up so initializing the cluster on it."
ssh $i "\$HOME/bin/cluster-setup.sh"
fi
done
}
I read about =i{ but it has no effect for me.
Thanks!
Last edited by graysky (2011-06-18 14:32:18)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
You need to put in your .vimrc
set autoindent
filetype indent on
Offline
Also, be sure to read the help topics 'cinoptions', cinoptions-values and
C-indenting. If you should run into any problems, the guys over at freenode's
#vim channel are very helpful and eager to help out
Edit:
Oops, just realized this is shell script code we're talking about... My bad.
Last edited by the_isz (2011-06-18 19:47:14)
Offline
graysky,
If you want vim to autoindent while typing, customize your ~/.vimrc file. I posted mine here: http://linuxandsuch.wordpress.com/2011/06/19/my-vimrc/ a few days back. I recommend all the options.
However, if you want to indent an already existing file use the indent program. Install with
sudo pacman -S indent
And then, to indent your file, run:
indent myfile.c
I'd recommend reading the manpage for indent to learn to tweak it to your coding style though .
Offline