Entries Tagged 'Unix' ↓

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

Function

h

Move Left One Character

j

Move Down One Line

k

Move Up One Line

l

Move Right One Character

0

Move to First Character Of Current Line

$

Move to Last Character Of Current Line

+

Move to First Character Of Next Line

w

Move to Next Word or Punctuation Mark

W

Move to Next Word

e

Move to End of Current Word

E

Move to End of Next Word

b

Move Back to Beginning of Word or Closest Punctuation

B

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

Function

x

Delete Current Character

X

Delete Character Immediately Left Of Cursor

dw

Delete Current Word

10dw

Delete Ten Words

D

Delete To End of Current Line (also d$)

dd

Deletes Current Line

20dd

Deletes Twenty Lines

dG

Deletes From Cursor to End

u

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.