Sunday, December 30, 2007

Auto-fold Perl subs

Add To enable it, just put the line:
let perl_fold=1
n your .vimrc, _vimrc or ftplugin/perl.vim.

Once you open a perl file, you'll see all functions are folded. You can then move to a function and (space) or "zo" to open it, "zc" to close it, "zR" to open all folds (normal file) and "zM" to re-fold all folds. It makes skimming over a file a breeze.<
See :help folding or :help perl.vim

If don't want to use perl_fold option and think you can handle it manually use some thing like below,
Add this to your .vimrc file and it'll automatically fold perl functions (and possibly other languages that define a subroutine with "sub ...")

http://www.vim.org/tips/tip.php?tip_id=419

Monday, December 3, 2007

Assigning Backspace key to console Terminal

On some consoles like AIX when we hit backspace you get control characters.
So the below can be used to assign the backspace key to erase backwards:

$ stty erase ^?

where ^? is equivalent to pressing the Backspace key.

Thursday, November 29, 2007

Bash shell IFS Internal Field Separator setting and unsetting

When using your "for i in " and you want your "i" to contain
the whole lines instead of space separated fields use the below
at the begining and at the end of your shell script:


export OFS="$IFS" ; export IFS=$'\n';
[ SHELL SCRIPT HERE THAT WORKS on WHOLE LINES ]
export IFS="$OFS"

Wednesday, November 28, 2007

To Strip an xml file for duplicate entries

Basically it greps for all the tags and sorts and prints the duplicates with the below script:


cat *.map.xml | grep include |
sed -e 's/^.*file\s*=\"//' |
sed -e 's/\".*$//' |
sort | uniq -d

Sunday, November 11, 2007

for i ... do ... done bash shell script

This the most usefull shell script I have come across for most of my day to day work on unix:
the oneliner.txt is an ascii file with one entry per line.
I usually modify this file with a vim search-an-replace like:
:%s/^.*\///gc


for i in `cat oneliner.txt`
do grep $i *.map.xml > /dev/null
if [ $? -eq 1 ]
then
echo $i
fi
done