Entries Tagged 'Apple' ↓

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!

Common Shortcuts for OS X And Their Windows Equivalents

If you are new to OS X, there are a bunch of shortcuts that you’ll immediately recognize from Windows.  If you don’t use shortcuts at all, you really are missing out, as they are much faster than using the mouse in most situations.  I tout programs like LaunchBar and Colibri because they make your computer usage faster. It is no different for shortcuts built-in to the operating system, so you should really take advantage of them!
Here is a short list of the most common on both OS X and Windows:

OS X and Windows Shortcuts

OS X and Windows Shortcuts

Since Vista was launched, you can create keyboard shortcuts to your programs through the Shortcut Icons that a program creates.  You do this by:

  1. Right-Click the shortcut icon for the program
  2. Left-Click Properties
  3. In the “Shortcut Properties” box, find “Shortcut” tab and Left-Click on that.
  4. Left-Click the “Shortcut Key” box., and type in a letter you want to start the program.  For example, type P for Photoshop.
  5. The box should update to show CTRL-ALT-P, as all shortcuts created in this manner automatically must begin with CTRL-ALT.

OS X Common Unicode Symbols and How To Type Them

If you don’t have Unicode Hex Keyboard setup in OS X, please see here how to do so. You will learn how to find a symbol your are looking for, or you can use the chart below for some of the most common ones you’ll see throughout the operating system’s menus.














Forward Erase








Power Button



Copyright ©



Trademark ™



Registered ®



Euro €



Apple 


iPhone Doubles Contact List in OS 3.0

Prior to syncing your iPhone with MobileMe, be sure to turn off the syncing of your address book in iTunes or you will end up with double contacts when you view the list “All Contacts” in your address book on your iPhone. This may seem like a no brainer to some, but it had me baffled for a while.
I had an issue with the speaker port on my iPhone 3G, and sorry to say *cough*, it had to be replaced with a new phone under Applecare. I have had “MobileMe” since it was .Mac, so I was in the Apple Store with a fresh iPhone, ready to leave. No contact info in my phone, say wha?!? I don’t know about you, but I don’t memorize phone numbers. I rely on my phone to do that. So I sync up with MobileMe right in the store and I’m good to go.
Here’s the tricky part. I didn’t realize that if I already synchronized with MobileMe, iTunes would still add my contacts from my Mac, even though MobileMe gets it’s list from…my Mac. What I had to do was delete all of my email address information and re-sync with iTunes.
To avoid that mess, before you sync with iTunes, follow the steps below:
First, open iTunes. Go into Preferences in the File Menu, or hit ⌘-Comma. Under Devices, check the “Prevent iPods and iPhones from syncing automatically” checkbox:

iTunes Preferences--Devices

iTunes Preferences--Devices

Now you can plug in your iPhone, ad nothing will be automatically changed.

Next, select your iPhone in the Devices List,  and select the Info Tab at the top.  You want to uncheck any selections in that tab that would also be synced with your MobileMe account:

iTunes iPhone Info Tab

iTunes iPhone Info Tab

If you have doubled your contacts already, you may have to restore your phone in the summary tab, which is unfortunate, but sometimes worth it anyway.  I’ve read some posts about unhappy owners having to do this, as it takes some time.  Before you try that, you may want to sync/unsync whatever duplicate information you have stuck on your iPhone and see if iTunes will remove it.

If you have tried this to no avail, please comment below and I’ll try to help you sort it out.  If it worked, please let me know that, too.

Thanks for stopping by.  :)