Using Vim as a diff tool

Firstly I will start with why to not use diff. I am not suggesting a replacement, I have simply found that Vim offers a much better interface, that is available on most (*nix based) server environments for comparing and merging files side by side.

Getting started

vim -d file_original.txt file_new.txt

Your tool of choice here is vim -d, so if you like this as a ‘patch’ to diff, why not be naughty and alias it? I have aliased alias diff='vim -d' in my shell preferences.

Getting fancy

Wow, i can see the difference between 2 files, big deal! Try adding more files to the arguments, suddenly we have loads more power to compare multiple files, easily.

vim -d file_original.txt file_new.txt file_new_ammendments.txt

Commands

ctrl+ww - will let you navigate buffers.

When comparing just 2 files, these commands will be handy when you select the lines to merge

  • dp - diff put
  • do - diff obtain/get

If you are in multi diff mode, these may be handy as you need to write long hand commands;

  • :diffget 3 If you were in buffer 1, writing this command would obtain the difference in buffer 3
  • :diffpu 1 Again, write this in buffer 3 and it will place the change in buffer 1

Writing/saving changes
:wqall

Further Reading

Fixing a broken FileVault image on OSX

Apple FileVault Logo It all begins when i became somewhat frustrated when my Mac Book Pro became increasingly unstable.

If it was not alt-tabbing or trivial operations including opening new applications, everything and anything seemed to lock up my machine, almost as if MS Windows had somehow taken over Unix in an evil way.

I persevered with this poor standard of working/coping for just over 3 days, when the final straw came, i could no longer use my Instant Message client Adium or read my RSS feeds in Vienna. Time for me to go on a hunt to track down the culprit to the nagging issues.

My first thoughts were that something was going amiss with the application preferences; as Vienna no longer knew what feeds i was once subscribed to and it was as if Adium had some form of Amnesia, prompting me to set up an IM connection for the `first time`.

Time to investigate

ls -las ~/Library

This is a problem, but an odd one. I had no results from my previous ls. How could this be? Well i consulted with a fellow system engineer and colleague, Giles Rapkin, whom advised me to do a disk checkup. Great idea, so i went off, firstly restoring permissions (just in case), no joy there, so disk check it was.

The disk check returned no conclusive results. So came the thought, could it be a problem with FileVault?

I logged out of my account, and logged in as root on my machine. I then dragged my FileVault image from /Users/$$USER$$ to Disk Utility and did a disk check. This returned my problem; i had a corrupt FileVault image. This was most likely caused by doing a hard reset whilst my machine was still doing stuff when the image was mounted.

Sorting out the problem

Problem diagnosed, time to move on and deal with the matter of getting my machine up and running in a stable fashion again.

Note, my solution will suspend the use of Filevault, see a guide on Encrypt your homedir on your mac without FileVault by Stuart Colville

Steps taken to fix my broken machine:

  1. Ensure you are logged in as root (Enabling and using the “root” user in Mac OS X)
  2. Mount the FileVault image from the account directory
  3. Copy all the files to a backup location: sudo cp -r /Volumes/$$USER$$ /Users/$$USER_backup$$
  4. Check the backup worked: ls -las /Users/$$USER_backup$$
  5. Delete the user in question in from the Accounts preference pane
  6. Create the same user again, still in the Accounts preference pane
  7. Copy all the backup files over to the newly created user: sudo cp -r /Users/$$USER_backup$$ /Users/$$USER$$
  8. Change permissions on the moved files: sudo chown -R $$USER$$ /Users/$$USER$$
  9. Logout of root and log back in to $$USER$$

Conclusion

This seemed to fix the problem and luckily everything is up and running again, smoothly, and this time without FileVault.

A bit about Carbon Silk

Its a design/development centric site by James Broad, a London based web developer working at Yahoo!. I create compelling sites and applications for the web.

Categories

You may also like

Social Stuff

Email:
jb@carbonsilk.com
Linked In:
http://www.linkedin.com...
Twitter:
http://twitter.com/kulor
Del.icio.us:
http://del.icio.us/kulor