Then they refused to give me good raises the next 2 years. My skills were increasing faster than ever, and I was the only guy who knew the entire system inside and out. Everyone in the company came to me when there was a problem because I knew how it all fit together. (I did not hoard this knowledge... Others were disinterested in having it, or didn't stay long enough to matter. I was unable to pass it on, and documented as much as I could at all times.)
So at 5 years, at my review, I asked for a raise. The answer was that if I "really cared" I should go talk to my boss's boss. ... Seriously? After some arguing, my boss eventually told me that they would be looking to correct everyone's salaries within a year.
Faced with the knowledge that they intended to knowingly screw me for a year, and then possibly continue afterwards, I started replying to the job offers that had been coming in. I had previously been ignoring them.
Right away, I found a company that looked good, and signed on. For a 40% pay hike. I had known I was underpaid, but didn't realize it was that much.
6 months later, the pay raises came in at the old job. A friend who was making what I made (!) got a 20% increase. He managed to find get a job offer at the same rate I was now making, and took it back to them. They refused to match it.
And in case that wasn't insult enough, they put out a job ad for 7 new people at the rate I was now making. The rate my friend tried to get them to pay. Their existing, experienced, efficient works were worth less to them than random people off the street.
I told my new boss about all this and he gave the same advice that a lot of people here gave: Do not accept a counter offer. IF the company gives one, they intend to replace you soon with someone who won't hold them hostage. Because that's how they see it. You are demanding that they pay you more, or you'll quit and leave them short of staff until they can find a replacement. They can't take the chance that you'll do it a second time, so you're out of there as soon as they can make it happen.
And he's right. I'd do the same thing in his position. All he needs to do to avoid that problem is to pay me properly, and that's happening. It's so simple.