sublime text- "list lines containing 'find' string - sublimetext2

How do I list the lines that contains the matches from the "find" command ? ie., I would like to list all the matching lines in a separate window. Currently one can only goto next / previous 'find'.

Try 'Find in Files' (Cmd+Shift+F on a Mac, presumably Ctrl+Shift+F on a PC).
Search results will display in a new tab, and you can double-click any result to jump to that line in the matching file.
To search only open files, put <open files> in the Where field.
To show only the lines that matched without surrounding lines for context, toggle the 'Show Context' option (to the left of the 'Find All' panel).

1.Here is a reference: How can I filter a file for lines containing a string in Sublime Text 2?
Hit Ctrl+F(⌘+F) to "Find All" occurences;
Hit Ctrl+L to Expand All Selection to Line.
Then you can Ctrl+C(⌘+C) or Ctrl+Shift+K(⌃+⇧+K) to
copy/delete the lines.
2.There's now a plugin for filtering lines:
https://github.com/davidpeckham/FilterLines
It allows filtering and code folding based on strings or regular expressions.

I think the simplest way is just to search for the line like this -> ".*find_this_string.*" and make sure that regular expression is ticked. Then you can click "find all" (alt+enter) and just copy and paste all results to a new window.

Related

How do I prevent Sublime Text 3 from auto-indenting a line as a one off

When I'm editing HTML or CSS in Sublime Text 3 the lines auto-indent when I hit the [ENTER] key, which generally is very useful.
On occasion I find myself wanting to paste a line of markup which is already indented, and this results in double indentation.
Is there some other key combination along with the [ENTER] key that prevents the next line from auto-indenting and instead returns the curson to the very beginning of the line? Please note I don't want to turn off auto-indent on a global basis.
You can do it in various steps, using various keybindings, so you can simply record a macro and do it in one simple custom keybinding (tools > record macro).
Steps:
Press [Enter] to move to a new line.
Press [shift+home] to select until the beginning of line (spaces or tabs used to indent).
Press [backspace] to remove the selected indentation charaters
You're done. Stop recording and save the macro, then use a custom keybinding to do it in a single step.
I found in Windows that CTRL + SHIFT + V (rather than just CTRL + V) does a "paste and indent" whereby the indentation is corrected as necessary.
It's also possible to switch the default paste for paste as indent as per these instructions: https://gist.github.com/twosixcode/1988097

Option highlighting all strings matching actual selection in PhpStorm?

Is there an option highlighting all strings matching the actual selection in PhpStorm (like in SublimeText) ?
You can use Ctrl + Shift + F7 for this in PhpStorm.
This will highlight all usages of selected text.
Using built-in functionality: select text and hit Ctrl + F that will bring "Find in page" functionality: it will highlight all matches of selected text in this document. But it's not always convenient as you have to hit extra keys and have "find in page" bar open...
You can install and use BrowseWordAtCaret plugin that will automatically highlight word under caret in whole document (regardless of it's nature -- variable or just plain text) + you can easily navigate between all matches.
P.S.
You have mentioned that "I'm used to regularly change the name of an object property, an array key or a parameter name at multiple places in same document."
Consider using Refactor | Rename for variables/class members/etc -- it works across multiple files.

Sublime Search/Replace adds New Line

When I do a simple search/replace, without any regex, ST2 adds a newline to each replacement. What am I doing wrong?
Below, I want to change spaces to commas. It does so, but also throws in a newline.
If the text you would like to replace is somewhat limited in size, here is a workaround. It doesn't even incorporate the builtin replace feature, and it can be somewhat slow for large text files.
Hit CMD + F (or CTRL + F) to bring up the Find dialog on the bottom of the window. Enter whatever string you'd like into the text field. Click the "Find All" button, and you'll get multiple write positions into the file. You can write in two places at once! If you've done it correctly, you'll see not just one blinking vertical line (which usually indicates the position in the file that the read/write pointer is at), but multiple. You can then type as usual into the file, and it should add text in multiple places.

Search and replace selectively across whole project in Sublime

I need to change occurrences of a term only in certain places in my project.
Is there a way in Sublime Text to navigate the search results (across an entire project) and only replace the occurrences of my choice?
⌘ShiftF opens the "search and replace" for the entire project, but the Replace button only gives me the option to replace all occurrences.
If you press the ... button in the search panel, a menu will open that allows you to refine your search. You can use the Where input field with a search pattern, or some tags like <open-files>.
http://docs.sublimetext.info/en/latest/search_and_replace/search_and_replace_files.html
Other than that, if you really need human input to decide where to replace and where not to replace, you can go to the next result by pressing Enter and pasting the code manually.
Just in case you didn't know: when you make a project search a new text file opens up with all the occurrences. You can click those occurrences to navigate to the file in question.
For posterity, the functionality to search/find and replace inside the open project does exist. ⌘ShiftF and add <open project> to the Where input field.

In Sublime Text, how do you increase the number of lines of context returned by "Find All"?

I am using the "Find All" feature in Sublime Text and I want to see a few more lines back from the find results. I can't find a setting for this -- is there any way to do this?
To expand upon DarkWater's comment to your question:
Add new lines with a regex before and after your search string:
.*\n.*\n.*search_string.*\n.*\n.*
This will match 2 new lines before and after your search_string.
Make sure you enable regular expression searching in the find dialog. Also make sure that you escape any regex special characters in your search_string.
Are you using the Find in Files… command from the Find menu (SUPER + SHIFT + F)?
If so, there's an option in the find panel to see more lines than the result line alone -- the next to last button (there should be 5 option buttons in the find panel), which has a "Show Context" tooltip, should do the trick.
To expand on the solutions provided by #dasl and #zaboco
I found that this variation was more suitable.
Example:
(.*\n){0,2}.*search_string.*(\n.*){0,2}
This will match 0-2 new lines before/after your search_string. Adjust numbers as needed to provide more/less context, but always keep the 0 as the first number in the quantifier.
Again, make sure you enable regular expression searching in the find dialog.
(The original regexes required that 2 lines above/below are present in the files, and excluded some necessary files from the search results)