Entries from November 2009 ↓

Moving Around in Vim

I’ve written a couple of beginning UNIX for OS X entries, such as creating a .bash_profile and .bashrc file using vim.  Here is another vim tutorial for moving around in the screen editor, so you can see just how powerful it’s commands can be.

This post will deal with mostly command mode, the default mode when you open vim (or an existing file with it.)  To move the command marker around the file without entering INSERT mode consists of four basic keys.  Moving to the next/previous word, to the beginning of a paragraph, etc. will require a bit more memorization.

You want to first familiarize yourself with the h, j, k, and l keys.  The outer two (on a standard keyboard) move your cursor left or right one-character;  h, to the left, and l to the right.  j will move your cursor up to the next line, while k moves it down one line.  The fact that you are in command mode means no changes are made to your text at this point.  You can use the arrow keys for the same functionality, but getting used to the keys will help you keep your hands where they belong–typing and editing text.

Moving to the beginning of the current line is done by pressing O (zero).  To move to the end of the current line press $+ moves your cursor to the beginning of the next line, and – moves you to the beginning of the previous line.

Next are some basic ideas for commands.  Some will take a number argument, followed by a command.  Some can be written with a number argument followed by another command.  For example, x in command mode means delete a character.  To delete a word, or the rest of a word if you are in the middle of one, you type dw.  If you precede x with a number, n, vim will delete the following n characters from the line.  The command to delete the next four characters would be written, simply, as 4x. To delete the next four words, you would type 4dw.

Vim is a very capable text editor once you learn more about its commands, and get used to bouncing between INSERT and command modes.  Below you can find a table of common commands and their function, at least enough to get you on your way as a skilled vim user.

Movement Command



Move Left One Character


Move Down One Line


Move Up One Line


Move Right One Character


Move to First Character Of Current Line


Move to Last Character Of Current Line


Move to First Character Of Next Line


Move to Next Word or Punctuation Mark


Move to Next Word


Move to End of Current Word


Move to End of Next Word


Move Back to Beginning of Word or Closest Punctuation


Move Back to Beginning of Word


Move to End of Current Sentence


Move to Beginning of Current Sentence


Move to Start if Next Paragraph


Move to Start of Previous Paragraph

Delete Command



Delete Current Character


Delete Character Immediately Left Of Cursor


Delete Current Word


Delete Ten Words


Delete To End of Current Line (also d$)


Deletes Current Line


Deletes Twenty Lines


Deletes From Cursor to End


Undo (doesn’t work for single character deletion)

Cron Jobs on OS X

Since OS X Tiger, cron has been replaced by a utility called launchd, and three separate launch daemons. Rather than having to run crontab  to manipulate scripts, they are run by launchd according to three separate directories inside of /etc/periodic.
The scripts contained in these folders are run at specified intervals by three preference files, in XML format, found in the /System/Library/LaunchDaemons folder. You can manipulate the .plist files with a text editor or Apple’s Property List Editor (if you’ve installed Developer Tools.) They are named, simply enough, com.apple.periodic-daily.plist, com.apple.periodic-weekly.plist, andcom.apple.periodic-monthly.plist. They are, by default, set to run at the same time as the old cron jobs, in the middle of the night. If you happen to shut down your Mac, it might be a good idea to change these intervals to a time when you’re sure the computer will not be shut down, as these jobs are important.

You will find a script in each of these folders called 999.local.  This file is set to read-ony by default, and is for  ”backwards compatibility  with the old /etc/daily.local” according to the comments in the file.  (I’m running Snow Leopard.)  I’d recommend not modifying the scripts in the /etc/periodic folders, and creating a /etc/daily.local, /etc/weekly.local, and /etc/monthly.local file for your cron jobs, as you have the 999.local script in each of the daily, weekly, and monthly sub-directories of /etc/periodic to tell your scripts to run.  Any future system updates could change the default files in those three directories, so if you modify those you may end up losing your scripts. Avoid that by setting up your own.

If you are running aTiger, the 999.local file may not exist, and you will have 500.daily, 500.weekly, and 500.monthly files inside their appropriate /etc/periodic directories.  You should still create a daily.local, weekly.local, and monthly.local script file and place them in the /etc directory, and they will be called  from the respective 500.* file.

Stop error c0000218 Hive file Corrupted or Missing

I was searching around for this error on an older Dell 8300 running Windows XP.  It seems Microsoft’s KB Article doesn’t have a fix for someone with an OEM installation of Windows XP.  Also, it doesn’t mention anything about the SECURITY file mentioned in my stop error message.

The problem here was a pretty bad virus infection.  What I was able to do to fix it and get Windows to boot, was to pull the drive and connect it to another Windows machine and run chkdsk.  I probably could have used my XP Pro CD and run chkdsk from the Recovery Console, but I’m going off the assumption that if you have an OEM CD, this feature may not be available to you. If you have it, run chkdsk /f at the command line. Otherwise, connect the drive to another machine running XP or better via USB and run it from there. To access the drive, you need a USB enclosure and a computer running XP, Vista, or 7.
In Windows, type Windows Key+E to access Explorer. Find your newly connected drive in the left-hand column and right-click to open the menu. Click on Properties. Click the Tools tab, and then click Check Now. Be sure to check for bad sectors and file structure errors, even though it takes a little longer for the sectors check…mine had bad sectors. After it finishes, if it’s found and corrected the errors, you should be able to boot into XP when you reinstall the drive to the problematic computer. From there, be sure to pick up Malwarebyte’s Anti-Malware and either Kaspersky Anti-Virus or NOD32 Anti-Virus, as you probably have a case of the virus blues.

I highly recommend you get Dr Web’s LiveCD, a bootable anti-virus disk. The image you download will be in .iso format, so be sure you can burn it to a CD from the computer you are using. I assume, if you’re reading this, you do have access to a bootable computer :)

There are a few things you should do, once you get your computer back to running condition. 
First, get off Internet Explorer!  Use a browser such as Firefox or Google Chrome.
Second, be sure to get yourself a paid for subscription to one of the above mentioned anti-virus programs. Obviously the one you are (or lack of one, for that matter) using isn’t effective. Good luck getting up and running, and thanks for reading!

Time Machine Not Backing Up Anymore? Try iBackup Instead.

[Check out iBackup here, if you hate to read.]

Well, what I thought was totally awesome the first time I ran it turned out to be not so good.  OS X’s Time Machine let me down, and for the past three days I’ve been searching for a way to fix it.  I managed to make a full backup to my FireWire drive the first time I ran it, and it seemed really cool.  I am backing up to an external FireWire 400 drive, and trying to backup my MacBook Pro.

This is a notebook, and keeping Time Machine running didn’t seem like such a great thing for me.  Keeping an external disk tethered to my MacBook Pro wouldn’t win any awards for mobility, for sure.  I backed up, turned Time Machine off, and ejected my external drive.  I was happy.  A week later, I mounted the FireWire drive, and all seemed well.  Turned on Time Machine, and it recognized the backup, I could flip through hourly backups, and it all looked great.  I tried to run a new backup before going off to sleep, however, the next morning only 27KB had been transferred.

Obviously something went awry.  No errors, no warnings, and the little backwards running icon in the menubar was still happily plugging along.  What was apparent, though, is Time Machine had failed miserably.  As I’ve looked deeper into this across many a forum, as well as various blogs, this is widespread and most users with difficulties such as this have moved to Snow Leopard 10.6.1.  If you are running 10.6.0 and don’t have any issues with Time Machine, don’t update to 10.6.1.  I did run across one cool widget that tells you Time Machines logs, called Time Machine Buddy.

I tried various things, from deleting the com.apple.timemachine.plist file in the Macintosh HD –>  Library –> Preferences folder.  This is a system-wide application and you won’t find a plist file in your home directory.  I tried deleting the partial backup from my FireWire drive, and the alias file as well.  I checked the .Trash folder on the FireWire drive to be sure there weren’t any remnants on the drive.  Reboot after reboot, unmount and mount, nothing would fix it.  So, as a last resort, I formatted the FireWire drive and started over.  I made sure it was set up by the book.  Nothing works to fix it, and the weird part is I never get an error.  On my last attempt before looking into alternatives, I waited 6 hours to transfer 11KB.  The furthest I ever had gotten was 5GB, which I thought would be it.  Nope, stuck there for eternity.  So, until Apple helps us out and gets it fixed, I’m moving on.

I found this sweet donationware application called iBackup.  It doesn’t do nearly what Time Machine is supposed to, but for someone like me who just wants to backup my home folder, where my Sites, Downloads, Documents, etc. reside, it seems like it’s going to work out beautiful.  14GB of data transferred over to my FireWire drive in about 20 minutes, with no headaches.  I like that.  And it’s free for personal use, although I will probably throw the creator a donation because it’s what you should do when someone writes a handy application that you are going to keep using for eternity.  I want them to keep publishing it, of course!
So here are some screenshots, you can read more about the Preferences and Plugins following the images (click to enlarge):

Main iBackup Screen

Main iBackup Screen

System Settings Plugins

System Settings Plugins

Profile Preference 1

Profile Preference 1

Profile Preference 2

Profile Preference 2

Profile Preference 3

Profile Preference 3

Profile Preference 4

Profile Preference 4

Profile Preferene 5

Profile Preference 5

Profile Preference 6

Profile Preference 6

iBackup doesn’t support incremental backups, however, it does only copy items that have been modified.  It uses straight up UNIX commands to copy your files, which you can see in the screenshot directly above, labeled Profile Preference 6.  iBackup, on the initial backup uses the ditto command, and for subsequent backups (I’d rather they called them “synchronizations”), it uses rsync.  As Apple has developers moving away from resource forks, rsync will be an easier tool to use for OS X consumers.  If you hate the Terminal, this backup solution makes it quite easy to use a complicated command.

Other features I like to see, that Time Machine completely lacks, are the ability to backup to Windows hosted shares, via both AFP and SMB servers, ethernet connected drives, as well as encrypted sparse images.  Quite nice.  I must admit, I was going to try Time Machine down the road if I see Apple has fixed it’s problems, but something like iBackup for Mac is a product that will be tough to get me away from.  Being able to use ethernet connected drives on my Gigabit network will certainly be a necessity; since I already own some LaCie drives, I never planned on buying a Time Capsule anyway.