2

So, the highlighduplicate plugin for sulbime text does not seem to work for me so I'd like to create my own. I need this to identity duplicates so it's a step further than Sublime's 'Permute: Unique'

I've created a regex expression: ^(.*)(\r?\n\1)+$ that will find duplications and it seems to work well.

Now, all I need is quick keyboard shortcut to trigger it. I tried recording a macro (using cmd+i) but it didn't seem to take even after multiple attempts.

I know sublime packages are written in python but I'm not well-versed in Python.

How would I write this plugin/package?

Thanks,

  • It doesn't appear that this is possible to complete with Sublime's Macro support. The function list for Macros doesn't list the ability to perform a search for a regular expression. docs.sublimetext.info/en/latest/reference/commands.html – Dracs Aug 12 '14 at 1:13
  • Do you know how I would do this with a package/plugin? – user2544542 Aug 13 '14 at 7:00
0

I found a Sublime Text Package which I believe we be able to do what you'd like.

RegReplace

It's listed under package control so it easy to install. It allows you to create commands to perform regular expression search and replaces. To have it run the commands you want you'll need to enter the following into the settings files.

User Settings

{
    "replacements": {
        "duplicate_lines": {
            "find": "^(.*)(\\r?\\n\\1)+$",
            "replace": "",
            "greedy": true,
            "case": false
        }
    }   
}

Command Settings

[
    {
        "keys": ["shift+ctrl+g"],
        "command": "reg_replace",
        "args": {"replacements": ["duplicate_lines"], "find_only": true}
    }
]
  • Thank you! I tried the steps but unfortunately, nothing happened. I change the shortcut to a different combination, checked the console to ensure nothing else was being invoked but still no luck. I then modified the regex to something simpler but still nothing. There are also no menu items coming up for me in cmd+shift+p to execute 'duplicate_lates'. Did I miss something? – user2544542 Aug 13 '14 at 11:03
  • Hmm... Sorry, should have done some extra testing before posting. I had it working by adding the "caption" value which causes it so show up in the command menu. I didn't actually test the hotkey, that's not working for me either. – Dracs Aug 13 '14 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.