Entries Tagged 'Uncategorized' ↓

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!

Using vim In OS X — A Text Editor Tutorial For Beginners

Here is a quick tutorial for people unfamiliar with text editors in UNIX.  If you are just getting started with the Terminal in OS X, you probably need to create your .bash_profile and such, so that you can keep your settings upon logging out of the shell.  I will show you how to create this file in a text editor called vim, which stands for vi IMproved.

Vim is  a very powerful text editor, and if you have any experience in UNIX at all, you probably were shown pico, which is easier to use at first due to some of the commands being shown at the bottom of the screen as you work in pico’s buffer.  In pico, there is no separation from command or input modes, also making it a bit less confusing.  The buffer simply means what is shown on your screen, not yet written to disk.  While a GUI text editor such as Microsoft Word or Apple’s Pages do not tell you that you are working in a buffer input mode, technically it is the same thing.  If they crash, you lose what you changed if it was not saved prior to the crash.

Vim is a little obscure, yet extremely functional.  You start vim by typing vi or vim at the bash prompt in Terminal.  Terminal is located in your ~/Applications/Utilities folder by default on OS X.  When it opens, you are by default in command mode.  Vim shows you this startup screen, which has a bunch of tildes (~) on the left-hand side, and some version information in the center:

vim Startup Screen OS X Snow Leopard

vim Startup Screen OS X Snow Leopard

If you type something in, the startup screen goes away and the first tilde also disappears.  The tilde characters simply clarify lines in the buffer.  They will not print, they are just there showing you where the next lines are.  Once started, you are by default in Vim’s command mode.  If you type vim testfile.txt at the bash prompt, vim will open the file testfile.txt in whichever directory you are currently in.  If testfile.txt doesn’t exist, vim will create the file and open into the edit buffer for you, skipping the welcome screen:

Vim Buffer

Vim Buffer

As shown in the screenshot (click to enlarge it, as with all screenshots on this blog), the buffer is in INSERT mode.  By default, no matter what file you open or create, vim starts in command mode.  It doesn’t ever show —COMMAND— at the bottom of the screen.  Vim lets you know you aren’t in command mode by telling you that you are in INSERT mode.

To get back into command mode, which is where you will end up saving files to disk, changing the contents of vim’s 26 named buffers (consider them like the clipboard in a GUI text editor), moving around the screen, deleting lines, etc.  Anything you want to do with the file besides type in text will generally be done in command mode. Let’s save this file now, so you can see how it works to get in and out of command mode.

First, hit the ESC key.  On almost every keyboard ever, this will be the key  at the very top-left corner of the keyboard.  You should no longer see –INSERT– at the bottom of the Terminal window.  Now type the following command, without the quotes:  ”:w testfile.txt“.  See screenshot below:

Write Command

Write Command

File Saved

File Saved

You can see at the bottom of the Terminal window that the write command was successful.  You also see that three lines were written containing a total of 138 characters.  You can verify the file was written by typing (again, without quotes) “:q“, and hit enter.  This quits vim.  At the bash prompt, type “ls” and hit enter.  You should see your new file in the list of the directory.  To remove (delete) the file, type “rm testfile.txt” and hit enter.

Now to create your .bash_profile, so you can save certain settings.  When Terminal starts, it will read this file to load alias information, screen settings and such, if they are explained in this file.  As you become more familiar with the Terminal and start to have preferences for certain things, i.e., showing hidden files when you get a list of a directory, you may want to create an alias for the ls command so it shows them by “default” because of your .bash_profile.

First, navigate to your home directory if you are not there now.  You do this by typing the command “cd ~” at the bash prompt and hitting enter.  Terminal will show your computer name, followed by your present working directory, and yourusername$, which is the bash prompt.  You should see something like this:

Bash Prompt

Bash Prompt

Create your empty .bash_profile by typing “vim .bash_profile”  and hitting enter.  We will create a simple alias and save the profile.  Then we will quit Terminal, restart it and verify the alias still works.

Alias in Profile

Alias in Profile

By default, the alias wouldn’t work again after you quit Terminal.  If it is in your profile, it will work when you open a new Terminal, such is the point of having a profile.  To type in what I show above, press the letter “i on your keyboard to put you in insert mode.  Then type the following exactly:

dirA=”ls -lia”

Hit the ESC key, and type: “:w” to save the file.  Now type “:q” to exit vim and return to the bash prompt.  You can verify the file was written and it’s contents by typing “cat .bash_profile” and hitting enter:

Verify File Was Written

Verify File Was Written

Now quit and re-open Terminal.  You should now be able to get a detailed list of your directory, showing hidden files, by typing dirA and hitting enter:

Working dirA Alias

Working dirA Alias

Next time I will show you how to navigate through text, delete lines and add or retrieve lines to and from the named buffers.  If there are certain things you would like to learn about Terminal or vim, please leave comments below.  Please also let me know if any of this could be better clarified, as I check my comments often and will respond promptly.  Thanks for reading!