#!/usr/bin/perl

use strict;
use Term::ReadKey;

my $tipfile='/usr/share/vim/tips.txt';
my $term_lines=20;
my $numtips=`grep "^VimTip [0-9]" $tipfile | wc -l`;

my $tip='VimTip ' . int(rand($numtips));

open IN, $tipfile or die("$!\n");
my $count;

LOOP:
while (<IN>) {
	if ($_ =~ /$tip/) {
		print;
		while(<IN>) {
			$count++;
			if ( ($count % $term_lines) == 0) {
				ReadMode 'cbreak';
				my $key = ReadKey(0);
				ReadMode 'normal';
			}
			last LOOP if /^VimTip/;
			print;
		}
	}
}

__END__