Sublime 3: text selection without line numbers (from finding all results)

I found everything in the project directory and got the following result:

/home/yusuf/Downloads/concept/concept/css/style.css: 234 position: relative; 235 } 236: .scrolled .fh5co-nav { 237 background: #fff; 238 padding: 10px 0; ... 241 box-shadow: 0px 5px 7px -7px rgba(0, 0, 0, 0.15); 242 } 243: .scrolled .fh5co-nav a { 244 color: #000; 245 } 

How to select text without line numbers? Is there a way to hide line numbers in search results? I want to select a code and paste it in another place.

+5
source share
3 answers

There is no (documented) option to hide line numbers in search results in files. To avoid copying line numbers, you must either carefully use multiple selections to copy all lines and skip numbers, or use search and replace, as Danil mentioned in his answer.

However, with a bit of plugin code, you can get the best of both worlds by creating a sublime heavy lift for you.

For example, select Tools > Developer > New Plugin... in the menu and replace the contents of the buffer with the following python code, then save it, for example. find_results_copy.py . It should be in your User package (the name does not matter, only the extension), but Sublime should take care of this automatically if you use the menu item to create a stub plug-in.

[edit] The plugin code has been modified to use a single regex operation, which (due to late night brain fart) was originally implemented using two operations. [/ Edit]

 import sublime import sublime_plugin import re class FindResultsCopyCommand(sublime_plugin.ApplicationCommand): def run(self): sublime.active_window ().run_command ("copy") sublime.set_clipboard (re.sub (r"^\s*[0-9]+.", "", sublime.get_clipboard (), flags=re.MULTILINE)) 

This implements a new command called find_results_copy , which first runs the default copy command and then modifies the contents of the clipboard with regular replacement of the expression to throw away line numbers.

Now you can implement a special key binding to invoke this command. Since we want this command to invoke a search for results, you can reuse the standard keyboard shortcut, modified to use our new command and with an added context that forces it to take effect only to search for results.

This example uses the keyboard command for Windows / Linux; if you use a Mac instead of super+c to match the standard key for this platform.

 {"keys": ["ctrl+c"], "command": "find_results_copy", "context": [ { "key": "selector", "operator": "equal", "operand": "text.find-in-files", "match_all": true }, ] }, 

Since this uses the default copy command, if you copy_with_empty_selection , it will copy the current line without a line number if you do not select anything if you are used to working this way.

If you wish, you can also duplicate this command (you can save it in the same file) and rename the class to FindResultsCutCommand and execute the cut (with the appropriate key binding) to also be able to cut the text and delete line numbers if you need to.

+3
source

The simplest solution is to open "Find & Replace" ( ⌘ βŒ₯ F on OS X, Ctrl H on Windows / Linux) and enter the following parameters (RegEx mode, find ^\s+[0-9]+ , replace empty)

Screenshot Sublime Text

+5
source

In the search results, double-click either the resulting file path or any txt line to open the source file for copying.

+2
source

Source: https://habr.com/ru/post/1259533/


All Articles