Copy Paste Killer
Sublime text 3 plugin to help to refactor duplicated code
Details
Installs
- Total 230
- Win 142
- Mac 68
- Linux 20
Feb 18 | Feb 17 | Feb 16 | Feb 15 | Feb 14 | Feb 13 | Feb 12 | Feb 11 | Feb 10 | Feb 9 | Feb 8 | Feb 7 | Feb 6 | Feb 5 | Feb 4 | Feb 3 | Feb 2 | Feb 1 | Jan 31 | Jan 30 | Jan 29 | Jan 28 | Jan 27 | Jan 26 | Jan 25 | Jan 24 | Jan 23 | Jan 22 | Jan 21 | Jan 20 | Jan 19 | Jan 18 | Jan 17 | Jan 16 | Jan 15 | Jan 14 | Jan 13 | Jan 12 | Jan 11 | Jan 10 | Jan 9 | Jan 8 | Jan 7 | Jan 6 | Jan 5 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Mac | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Linux | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Readme
- Source
- raw.githubusercontent.com
CopyPasteKiller Plugin
Sublime text 3 plugin to help to refactor duplicated code.
This command sets snippets for “Find and Replace” with regular expression.
You can find any code blocks without caring about indentation
and some differences like variable names.
You can replace those matches with refactored code
by changing the given 'replace_string' and hitting “Replace”.
Usage:
You can declare shortcut like:
{ "keys": ["ctrl+shift+i"], "command": "copy_paste_killer" }
Guide
Select lines
Run “copy_paste_killer” command
The snippets for “Find” and “Replace” are set
You could configure whether to open panels or not with settings keep_panels_open
Change the snippet for “Find”
Find parts which have variations(e.g. variable name) in the snippet for “Find” and select them
Replace variables with Regex
Replace variable name parts with Regex in the snippet for “Find”
You can name regex groups as you want
The typical format to name regex group is (?<name>.*)
Copy the snippet into “Find:”
“Select All ⌘A” -> “Use Selection for Find ⌘E”
Hit “Find” and confirm matches
You can find duplicated codes even if they have different indents and different variable names
Change the snippet for “Replace”
Change the snippet for “Replace” using regex groups named in “Find”
The format is $+{name}
Copy the snippet into “Replace:”
“Select All ⌘A” -> “Use Selection for Replace ⇧⌘E”
Hit “Replace” and confirm changes
Hit “Replace” and confirm if changes are expected
Check changes
Check changes with git diff
Reset(Undo) changes with git checkout
etc if replacements were wrong
Settings
keep_panels_open
(default true) - Configure whether to open panels for snippets or not
Test
UnitTesting plugin
- Open tests/test_copy_paste_killer_selection_converter.py
- Open “Command Palette…” (⇧⌘P)
- Run “UnitTesting: Test Current File”
Test scenarios
- “tests/data/*_source.txt” -> Expected snippet for selection
- “tests/data/*_find.txt” -> Expected snippet for find_string
- “tests/data/*_replace.txt” -> Expected snippet for replace_string
Manual testing
Any selection shouldn't change with “copy_paste_killer” command and “Find” and “Replace” when replace_string isn't changed.