Vim URL Shortener Summary: ----------------------- Long URLs can be awkward to deal with when emailing. This vim plugin and perl script will convert a long URL into a shorter one (Using www.makeashorterlink.com) at the press of a single button. If you have mutt configured to use vim as its editor then this can be used when sending email. The perl script can also be used stand alone to shorten / restore URLs. Installation: ----------------------- The vim URL shortener comes in two parts, a Perl script and a vim function. Short version: Assuming you are running as root and in the untarred directory. # cp masl.pl /usr/local/bin/ # chmod +x /usr/local/bin/masl.pl If you are using Debian you can run # apt-get install libwww-shorten-perl If you're not using Debian then run # perl -MCPAN -e 'install WWW::Shorten' Copy the contents of shorten.vim to your .vimrc Long version: The Perl script, masl.pl must be placed in your path and made executable. For example: cp masl.pl /usr/local/bin/ chmod +x /usr/local/bin/masl.pl The script itself only requires a single non-core Perl module, WWW::Shorten, which can be installed as per usual. The two main options for this are the cpan shell command (which is functionally equivalent to perl -MCPAN -e 'install WWW::Shorten' ) or downloading and installing by hand. If you use a Linux system with a built in package manager (such as RPM or apt then you can try installing with that. The vim function contained in shorten.vim needs to be placed in your .vimrc file, this typically lives in your home directory. By default the key will be mapped to call the shorten function, if this key is already in use simply find and change the following line: noremap :call ShortenURL() And replace with your own choice of key. Usage: ----------------------- The masl.pl script, by default, allows you to shorten a URL using the engine at www.makeashorterlink.com. The URL to shorten is passed in as the argument and the new, shorter one is returned on standard out. If anything goes wrong in the process (the URL is too short to shorten, the service is down etc) then the original URL is passed back out allowing the script to be used as a filter. If invoked with the '-l' option and an already shortened URL the script will return the expanded version. To see all the supported options you can either run the command with '-h' or no arguments. Once the installation is complete you can access the shortening functionality from within vim by moving the cursor to the URL you want to alter (Anywhere in the URL is fine) and pressing . Vim will then replace all occurrences of the URL with the new, shorter version before moving the cursor back to its starting position, or as near as it can get on the same line. Note: This script makes no attempt to determine what is a valid URL. If you're smart enough to be using vim then you are smart enough to only run this on actual URLs. If this is an issue let me know and I'll add some URL scanning to masl.pl to look for valid URLs and return a warning if it doesn't match. The WWW::Shorten Perl module this code uses was written by Dave Cross, Perl guru and all round decent chap. You can find him on line here: www.dave.org.uk/ and his module lives here: http://search.cpan.org/~davecross/WWW-Shorten/ Please note, Dave didn't write the code included in this little bundle so DO NOT hassle him with support requests, bug reports or loveletters. Especially not the loveletters, I want those. Unless you're male. TODO: ----------------------- Tidy up the docs. Add a lengthen function for vim, if anyone actually wants one. Add shorten scripts for other engines. -- just change the perl script. Create packages. ----------------------- Author: Dean Wilson Project Homepage: www.unixdaemon.net/vim-shorten.html Date: 2004/04/12 License: GPL