## Share Eclipse snippets among workspaces, or even different computers

I use Eclipse as my editor of choice. I also use multiple Workspaces (see File > Switch Workspace). I also use Snippets for common code templates.

I created some useful snippets in one workspace that I wanted to be able to use in another. Eclipse doesn’t provide an easy way to share snippets across workspaces. Using Eclipse, you would have to copy the snippet, switch workspaces (which requires restarting the program), and then paste it… for each snippet you want to reuse. And that’s awful.

## Phase 1: Copy the XML nodes

One way to copy a bunch of snippets across workspaces is to merge the various snippet XML files into a master file. Your snippets are stored in

C:\Users\YOURNAME\AppData\Roaming\Eclipse\workspace-YOUR_WS_NAME\.metadata\.plugins\org.eclipse.wst.common.snippets\user.xml

I was able to use WinMerge to compare my new snippets file with my older one. It was easy to use WinMerge’s Copy Left command to push just the new lines into my older file, and then save the merged master. Restarting Eclipse with the new master file confirmed that I successfully copied the snippets.

But wait a minute…. My snippets files are in sync, but there is nothing to prevent them from drifting out of sync again.

## Phase 2: Make a hard link

A hard link is a pointer. It looks like a file, but it doesn’t have any contents, it has a reference to another file, somewhere else on the file system. I can create a hard link called “user.xml” in each of my workspaces that points to a single, XML master file.

I saved my merged master XML file to a location outside of the Eclipse folder tree. Then I backed up my individual user.xml files by renaming them. Then I created the hard links.

mklink /H user.xml "C:\path\to\your\master\user.xml"