Remove duplicate lines

Created by jneuendorf
Last updated about 1 month ago
atom.commands.add('atom-workspace', {
    'custom:remove-duplicate-lines': () => {
        editor = atom.workspace.getActiveTextEditor()
        lineEnding = editor.getBuffer().getPreferredLineEnding()
        lines = editor.getText().split(lineEnding)
        dedupedLines = [...new Set(lines)]
        editor.setText(dedupedLines.join(lineEnding))
    }
})

Add this code to your init.js file. If you need a CoffeeScript version see https://coffeescript-cookbook.github.io for how to remove duplicate elements from an array in CoffeeScript (v1).