Juri Strumpflohner mainly operates in the web sector developing rich applications with HTML5 and JavaScript. Beside having a Java background and developing Android applications he currently works as a software architect mainly dealing with the .Net technology stack. When he’s not coding or blogging about his newest discoveries he is practicing Yoseikan Budo where he owns a 2nd DAN. Juri is a DZone MVB and is not an employee of DZone and has posted 51 posts at DZone. You can read more from them at their website. View Full User Profile

Find Code Duplicates with Sublime Text

  • submit to reddit
Code duplication is the worst practice ever, right? Well, actually there might be situations where duplicating can be better than factoring out, but these are very rare. But, before I loose myself in best practices preaches, here's a quick post about a possible way to use Sublime for identifying code duplications.Often, when I come across some conditions then it happens I see similar code pieces in each of the branches but it's often really hard to identify whether they really match in every part. So instead of going and comparing statement by statement, Sublime has this nice Ctrl+D shortcut which maps to the "Quick Add Next" command. What it does is to select the next match in the current document (btw. also adding multiple cursors, so you could directly edit each of the selections in parallel). So what you can do is to highlight a given code region, press Ctrl+D and look at how many matches there are:

Click the screenshots for a bigger view


The same can obviously be applied by searching in multiple documents. Again, just select the code part of interest and press Ctrl+Shift+F and then click on the "Find" button. This will present you a nice overview of all files with corresponding matches.

Simple but effective.
Published at DZone with permission of Juri Strumpflohner, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)