Sublime Forum

Is there a way to sort and/or remove duplicate lines?

#1

I have looked through commands and plugins and I have not found a reasonable solution as of yet. May be obvious, but I am very new to the editor and I am trying to phase out my old editor.

Thanks!

1 Like

#2

Edit -> Sort Lines (F9)

Edit -> Permute Lines -> Unique

5 Likes

#3

Hah, just found it and was going to delete it. Thanks!

0 Likes

#4

Hi,
I know this will be an easy question, but I am trying to find duplicate lines, I did the Edit - Sort Lines and then the Permute Unique, but I don’t see where the duplicates are? Is there a way to segment them or highlight them?

0 Likes

#5

hey, I know the thread is kinda old, but as I’m here, lets share a tip

I’m using the mac os version, so, my shortcuts should be different. Well, when I need to highlight duplicate values (even lines) I use the cmd+d to select them all.

Hope it helps you OP!

0 Likes

#6

You can use the Compare side-by-side package and use a duplicate tab of your file before using Ctrl+Shift+P, “Permute Lines” then “Compare with…” and select the original file.

The removed lines will be highlighted.

1 Like

#7

Ctrl+Shift+P -> Sort
Ctrl+Shift+P -> Unique

1 Like

#8

you can use this regex pattern to find duplicate lines:

^(.+)$\n^\1$
2 Likes

#9

There is also this package to remove duplicate lines.

0 Likes

#10

Edit > Permute Lines > Unique works fine for me, but is there a way I could assign this command a shortcut? We already have F9 to Sort Lines, after all … I’d hate to have to take my hands off the keyboard.

PS: There still is no comprehensive list of all available commands, correct?

0 Likes

#11

Since it’s available in the main menu, just use View Package File and view Default/Main.sublime-menu and find out where that item is. After finding that item, just use Preferences: Key Bindings from the command palette and make a custom binding for it

{
    "keys": ["<my_favorite_shortcut>"],
    "command": "permute_lines",
    "args": {
        "operation": "unique"
    },
},
0 Likes

#12

Thanks a lot! It’s actually permute_lines but that worked fine:

{
    "keys": ["shift+f9"],
    "command": "permute_lines",
    "args": {
        "operation": "reverse"
    },
},

{
    "keys": ["alt+f9"],
    "command": "permute_lines",
    "args": {
        "operation": "unique"
    },
},

{
    "keys": ["ctrl+alt+f9"],
    "command": "permute_lines",
    "args": {
        "operation": "shuffle"
    },
},

0 Likes

#13

Sorry. Looks like I did not look too closely at the command name. Edited the post to reflect

0 Likes

#14

No worries! Your reply was immensely helpful.

0 Likes