Sublime text найти дубли
Sublime Text is brim-full of editing features. This topic just scratches the surface of what's possible.
Multiple selections let you make sweeping changes to your text efficiently. Any praise about multiple selections is an understatement. This is why:
Select some text and press Ctrl D to add more instances. If you want to skip the current instance, press Ctrl K , Ctrl D .
If you go too far, press Ctrl U to deselect the current instance.
You can copy multiple selected lines to a separate buffer, edit them there, select the content again as multiple lines and then paste them back into place in the first buffer.
You can select a rectangular area of a file. Column selection makes use of multiple selections.
It's possible to add blocks of text to or remove them from the selection.
Windows & Linux
Description | Shortcut |
---|---|
Select Block | ⇧ + Right Mouse Button |
Add to Selection | Ctrl ⇧ + Right Mouse Button |
Remove from Selection | Alt ⇧ + Right Mouse Button |
macOS
Description | Shortcut |
---|---|
Select Block | ⌥ + Left Mouse Button |
Add to Selection | ⌥ ⌘ + Left Mouse Button |
Remove from Selection | ⌥ ⇧ ⌘ + Left Mouse Button |
System | Shortcut |
---|---|
Windows | Ctrl Alt ↑ and Ctrl Alt ↓ |
Linux | Alt ⇧ ↑ and Alt ⇧ ↓ |
macOS | Ctrl ⇧ ↑ and Ctrl ⇧ ↓ |
The list is long; all available options can be found under Selection. To name a few:
- Select subwords ( Alt ⇧ ← and Alt ⇧ → )
- Expand selection to brackets ( Ctrl ⇧ M )
- Expand selection to indentation ( Ctrl ⇧ J )
- Expand selection to scope ( Ctrl ⇧ ␣ )
Need to swap two letters or, better yet, two words? Experiment with Ctrl T .
The Edit, Selection, Find and Goto menus are good places to look for handy editing tools. You might end up using just a few of them, but the rest will still be there for when you need them.
вы можете легко найти повторяющиеся строки, запустив Sort Lines затем ищем это регулярное выражение, которое использует линейные граничные маркеры ^ и $ и обратная ссылка .
следуйте этому с помощью Find All, Copy, Paste в новой вкладке, Permute Lines / Unique и вы извлекли их.
к сожалению, у меня нет доступа к Sublime Text на данный момент, так что я не в состоянии проверить это, но я считаю, что что-то вроде следующего может работать для вас:
- сортировка строк через Edit -> Sort Lines команда
- установить Выделить Дубликаты плагин, и использовать его, чтобы выделить все повторяющиеся строки
- вырезать выделенные строки в буфер обмена и вставить их в новый файл
- строки, которые остаются в оригинале файл являются вашими Экстракт Уникального строки
- в новом файле выделите весь текст и удалите повторяющиеся строки через Edit -> Permute Lines -> Unique команда
- строки, которые остаются в новом файле, являются вашими Экстракт Дубликаты строки
слегка модифицированный ответ @MJH выше, чтобы получить дублированные строки с Sublime 3 и DiffMerge, без использования Highlight Duplicates плагин.
- сортировка строк через Sublime 3 Edit -> Sort Lines команда
- сохранить исходный файл как sorted_orig.txt
- выделите весь текст и удалите повторяющиеся строки через Sublime 3 Edit -> Permute Lines -> Unique команда
- сохранить измененный файл как no_dup_sorted.txt
- запустить дифф с помощью DiffMerge с sorted_orig.txt и no_dup_sorted.txt файлы.
- использовать Export -> File Diffs в DiffMerge чтобы получить список дубликатов в буфер обмена или сохранить в другой файл.
была такая же проблема (покажите мне простофили). не нашел простого ответа на основе Sublime и вернулся к использованию команд Unix (в моем файле были данные, которые я хотел найти дубликаты в Столбцах 11-56):
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?
It's been a long time since I played with plugins. But at the very least, here is some tips. You can install AAAPackageDev, it will provide the new plugin command, that will give you a raw skeleton in python. You can then create a shortcut to trigger the python command.
2 Answers 2
If it's not perfectly suitable for you, you can check out the code, it's quite easy~
I fixed the package for you, got here and install this new version.
Let me know if you have any issue, but apparently it works on my laptop.
To be a little more verbose, there was two issue with the file. First, a change in ST API made a call to add_regions() fail, and there was also a change in python API regarding defaultDict implementation.
You can look at the modification I made on github, or here is a quick diff:
Thanks so much for sharing this Xaelias. I gave it a shot it didn't seem to work. Here's what the console spit out: ` File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 271, in on_modified callback.on_modified(v) File "/Users/me/Library/Application Support/Sublime Text 3/Packages/HighlightDuplicates-master/highlight_duplicates.py", line 107, in on_modified highlight_duplicates(view) File "/Users/me/Library/Application Support/Sublime Text 3/Packages/HighlightDuplicates-master/highlight_duplicates.py", line 81, in highlight_duplicates
show_lines(duplicates.values(), view) File "/Users/me/Library/Application Support/Sublime Text 3/Packages/HighlightDuplicates-master/highlight_duplicates.py", line 71, in show_lines sublime.DRAW_NO_FILL) File "/Applications/Sublime Text.app/Contents/MacOS/sublime.py", line 861, in add_regions sublime_api.view_add_regions(self.view_id, key, regions, scope, icon, flags) TypeError: String required
@user2544542 It's weird, I don't get this error. Did you modify the settings file? If not, did you try with a simple file (like twice the same line?). It is to try and find what causes this issue. I also pushed a slight modification to the git repository. Try it, maybe it's that simple.
I have a problem in my favorite editor Sublime text, I can't do a duplicate line with the command Ctrl + Shift + d default, but if I change it, it works.
I don't want to change it, and i want that works for me.
Please any help, Thanks.
the python version on your machine has nothing to do with Sublime Text, which ships with its own internal version.
6 Answers 6
Check out @skuroda's FindKeyConflicts plugin, available through Package Control. You probably have another plugin installed that also uses Ctrl Shift D as a shortcut, and FindKeyConflicts will help you find out which, so you can change it and keep Sublime's default.
I'vd tested it but i didn't any conflict of this key, also I'vd re-install sublime text :S no results ..
@kach Try entering sublime.log_commands(True) in the console. Then hit your keyboard short cut. Can you tell us what command comes up?
ive tried this too. other keys and clicks is as expected. eg: ctrl+c it shows "command: copy". ctrl+shift+d shows nothing. "FindKeyConflicts: All Key Maps to Buffer" showing ctrl+shift+d binds to duplicate_line only
Sorry to bring this up, I know it's old, but I'm on the exact same situation. Apart from trying everything which was suggested before without any success, I made a really odd discovery by logging keyboard events to the console:
- If I press Shift + Ctrl + d , it does not work. ST does not recognize the keypress.
- If I press Shift + Ctrl + Alt + d , it works and ST recognizes the keypress.
- If, after pressing Shift + Ctrl + Alt + d , I lift my finger from Alt, pressing D repeatedly makes ST recognize Shift + Ctrl + d . I can also release Shift and press it again and still works. It works until I release Ctrl key. Then pressing again Shift + Ctrl + d does nothing, again.
Testing the same sequence out of the console, in the edition window, line duplication works again with this trick. Anyway, it's a pain in the *ss and I'm afraid there's some kind of bug in the key handling code. Hope this helps fixing it.
Both support regular expressions, a powerful tool for searching and replacing text.
Keyboard shortcuts related to the search panel:
Description | Shortcut |
---|---|
Open search panel | Ctrl F |
Toggle regular expressions | Alt R |
Toggle case sensitivity | Alt C |
Toggle exact match | Alt W |
Find next | ⏎ |
Find previous | ⇧ ⏎ |
Find all | Alt ⏎ |
Keyboard shortcuts related to the incremental search panel:
Description | Shortcut |
---|---|
Open incremental search panel | Ctrl I |
Toggle regular expressions | Alt R |
Toggle case sensitivity | Alt C |
Toggle exact match | Alt W |
Find next | ⏎ |
Find previous | ⇧ ⏎ |
Find all | Alt ⏎ |
The only difference between this panel and the regular search panel lies in the behavior of the ⏎ key. In incremental searches, it will select the next match in the file and dismiss the search panel for you. Choosing between this panel or the regular search panel is a matter of preference.
Keyboard shortcuts related to the replace panel:
Description | Shortcut |
---|---|
Open replace panel | Ctrl H |
Replace next | Ctrl ⇧ H |
Replace all | Ctrl Alt ⏎ |
These key bindings work when the search panel is hidden:
Description | Shortcut |
---|---|
Search forward using most recent pattern | F3 |
Search backwards using most recent pattern | ⇧ F3 |
Select all matches using most recent pattern | Alt F3 |
You can also perform searches based on the current selection:
Description | Shortcut |
---|---|
Search using current selection | Ctrl E |
Replace using current selection | Ctrl ⇧ E |
You can type in multiline search patterns into search panels. To enter newline characters, press Ctrl ⏎ .
Note that search panels are resizable too.
Keyboard shortcuts related to Find in Files:
Description | Shortcut |
---|---|
Open Find in Files | Ctrl ⇧ F |
Toggle regular expressions | Alt R |
Toggle case sensitivity | Alt C |
Toggle exact matches | Alt W |
Find next | Enter |
The Where field in Find in Files limits the search scope. You can define scopes in several ways:
- Adding individual directories (Unix-style paths, even on Windows)
- Adding/excluding files based on wildcards
- Adding symbolic locations ( , . )
It is also possible to combine these filters using commas; for example:
Press the . button in the search panel to display a menu containing scope options.
In the search panel, you can customize how results are displayed. These are the available options:
If the search yields matches, you can move through the sequence using the following key bindings:
Description | Shortcut |
---|---|
Next match | F4 |
Previous match | ⇧ F4 |
Open match | ⏎ |
You can also double-click on lines with a match.
Regular Expressions find complex patterns in text. To take full advantage of the search and replace facilities in Sublime Text, you should at least learn the basics of regular expressions. In this guide we won't explain how to use regular expressions.
The term regular expression is usually shortened to regexp or regex.
This is how a regex might look:
To use regular expressions in Sublime Text, you first need to activate them in the various search panels. Otherwise, search terms will be interpreted literally.
Sublime Text uses the Perl Compatible Regular Expressions (PCRE) engine from the Boost library.
(opens new window) Documentation on format strings. Note that Sublime Text additionally interprets \\ as $ .
Читайте также: