So far, so good: The S&P 500 has risen in 2023 with no major downturns. It's even possible that we could soon see the beginning of a new bull market.

However, a running gag in the Peanuts cartoons comes to mind. Every time Charlie Brown gets ready to kick a football, Lucy yanks it away at the last second. Investors could have the equivalent of this happen with the stock market.

It's quite possible that stocks could once again decline. But that's not necessarily a horrible scenario. Here are three top stocks to buy if there is a market pullback.

1. Dollar General

If the stock market indeed retreats, one of the most likely culprits is that investors fear a recession is coming. There are stocks, though, that are practically recession-proof. I think Dollar General (DG -0.34%) belongs in that group.

Dollar General recently opened its 19,000th store. The company's discount stores are located within five miles of close to three-quarters of the U.S. population. During a recession, you can bet that customers will increasingly search for the bargains that their nearby Dollar General store routinely offers.

I don't think that Dollar General is solely a market pullback/recession play, though. The stock performed very well during the roaring bull market and strong economy of recent years. My view is that it should do so if the U.S. avoids a recession and a new bull market begins.

Dollar General has several great growth opportunities ahead. Its DG Fresh program focused on frozen and refrigerated products should attract more customers to participating stores. The company also plans to nearly triple the number of its stand-alone pOpshelf stores, which offer a "treasure hunt" experience.

2. Enterprise Products Partners

Yes, Enterprise Products Partners' (EPD 0.21%) stock might fall if there's an overall market pullback. However, I think that would present a great buying opportunity for this midstream energy stock.

Enterprise Products Partners already offers a really attractive dividend yield of nearly 7.6%. If the company's share price declines, that yield will increase. Income investors should relish the chance to buy this stock at a discounted price.

Even better, the dividend is almost certainly going to grow. Enterprise has increased its dividend for 24 consecutive years. It's in a strong position to continue growing the dividend payout.

I don't like Enterprise Products Partners just for its dividend, though. The company also has solid long-term growth prospects as it adds pipelines and other midstream energy facilities.

3. Vertex Pharmaceuticals

Vertex Pharmaceuticals (VRTX -0.27%) could be the perfect stock to buy if there's a market pullback. Why? The company's business is insulated from the main factors that would cause such a decline.

There are only four approved drugs that treat the underlying cause of cystic fibrosis (CF). All four belong to Vertex. Physicians will prescribe the therapies to CF patients regardless of what happens with the stock market or the economy.

Vertex could also have some big news on the way. The company and its partner, CRISPR Therapeutics, hope to win regulatory approvals for exa-cel in treating sickle cell disease and beta-thalassemia. Vertex thinks the gene-editing therapy could generate peak annual sales of more than $2 billion if it's approved.

In addition, Vertex should have a near-term opportunity to launch non-opioid pain drug VX-548. The company is already evaluating VX-548 in pivotal late-stage testing that should wrap up by March 2024. 

There are even more longer-term growth drivers for Vertex. Inaxaplin is currently in a late-stage clinical study targeting APOL1-mediated kidney disease, which has a bigger patient population than CF. Vertex also is in early stage development with a promising therapy that could cure type 1 diabetes.