Separate search results panel for each search in sublime text 3? - sublimetext3

When I press command + shift + f, I can search for all instances of a string in an entire project.
But when I do it a second time, it brings up the second search in the same panel. This gets very messy very quickly when conducting many searches.
Question: How can I bring up the second (and subsequent) search results in their own, new panel?
Example: 5 searches would result in 5 result sets each of their own panels (i.e. 5 panels total). Also, if possible, I'd like to set this as a default for future if it's simple to do so.

There is currently no way to have different search results buffer for different searches. All of the search results would be appended in the buffer with the name Find Results.
If you want different different search result tabs, then you will need to rename the current search result buffer with a different name than Find Results i.e. Find Results (1). This way, the next time, you perform a find in files, ST would create a new Find Results buffer.
It's actually quite simple to write a small plugin that uses View.set_name() to set the name of the current buffer and then you can bind it to a key (So that you can just change the Find buffer name in one stroke and have other search results in new buffers)

Related

Find a file with all given strings on Linux

Similar to this question How do I find all files containing specific text on Linux? but I want all the files that contain multiple given strings (these strings not necessarily next to each other or on the same line, just in the same file).
My use case is I am looking at a UI and want to modify the file which controls this particular screen. The codebase though is huge and it is difficult to locate this file. All I have to go on is some of the hardcoded strings on this screen which I would like to do the search on. The strings are quite generic though such as 'Done', 'Close', 'View Details'... Doing a search on any of these strings individually, using the answer from the linked question above, brings back too many results but I think doing the search on all of them together will filter it down enough to find the file.

Creating a 4-5 character column along the left margin in vim

As a bit of context, I am considering making a plugin for vim that would inline specific debugging and/or profiling information on along the left margin (ideally left of the numbers column) which would need to be 4-5 characters wide. However, I cannot find any means to accomplish this. I've searched around, and the closest thing I can find is vimscript code for inserting signs in the sign column, but the sign column is fixed at 2 characters wide.
I've considered the possibility of making my own makeshift column (to the right of the numbers column, in the normally editable text area) and somehow marking it as readonly, but that doesn't seem possible either- from what I've read, the entire buffer must be readonly or not; you can't have just a portion as readonly.
For completeness here's an example. I would like to programmatically insert a 4-5 character column before some text (with numbers set)
1 Text buffer
2 with some
3 text
to make
My 1 Text buffer
own 2 with some
text 3 text
Is there any way to accomplish this task?
The built-in feature for this is the sign column, but yes it is limited to two characters.
Depending on your use cases, it might be okay to enhance the signs with a tooltip popup (:help balloon-eval explicitly mentions This feature allows a debugger, or other external tool, to display dynamic information based on where the mouse is pointing.), or maybe place the additional information in the quickfix or location list.
Modification of the actual buffer has many downsides (as it effectively prevents editing, and Vim's main purpose is just that). What some plugins do is showing a scratch (that is: unpersisted, unmodifiable) buffer in a vertical split, and setting the 'scrollbind' option so that its contents follow the original buffer. For an example, have a look at the VCSCommand plugin, which uses this for annotating a buffer with commit information.

How to search for files faster in Sublime Text 3

Right now I do ⌘t then scroll through autocomplete, or start typing the name (but half the time it doesn't find it).
Sublime doesn't find a file in many cases. For example, I typically have all my files called index.<ext> nested inside some folder. So I might have:
my/long/directory/structure/index.js
my/long/directory/structure2/index.js
my/long/directory/structure3/index.js
my/long/directory/structure.../index.js
my/long/directory/structuren/index.js
my/long/directory/index.js
my/long/directory2/index.js
my/long/directory.../index.js
my/long/directoryn/index.js
my/long/index.js
my/index.js
...
But in sublime you have to search for an exact path. I can't search this:
my directory index
And get results for directory, directory2, directory..., directoryn, I just get empty results because there is not my/directory. I can't remember the full folder path most of the time, so it takes a lot of effort to do so and I end up just navigating in the sidebar to find the file which takes some time.
Wondering if there is a better/faster way of doing this. Basically searching for a file by snippets/keywords of the complete path. So m dir would return my/long/directory, etc.
The first thing to note is that you do not have to search for an exact path; anywhere that Sublime provides you a list of items to select from and a text entry, fuzzy matching is in play. In your example searching just for idx will narrow down the list to all items that have those characters in that order, even if they're not adjacent to each other.
The entries show you visually how they're matching up, and there's a fairly sophisticated system behind the scenes that decides which characters make the best matches (relative to some hidden scoring algorithm):
In addition to this you can use multiple space separated terms to filter down the list. Each term is applied to the list of items resulting from the prior term, so they don't need to be provided in the same order as they appear in the file names.
This helps with searches where you know generally the name of the file, and from there can further drill down on segments of the path or other terms that will help narrow things down:
Something to note here is that as seen in these images, the folder structure is my/long/directory/structure, but the names of the files as seen in the panel don't include the my/ at the start.
In cases where your project contains only one top level folder, that folder isn't presented in the names of the files. Presumably this is because it's common to every file and thus not going to be a useful filter. As such trying to use my in the search field will return no matches unless one of the files has an m and a y somewhere in their filenames.
This isn't the case if there are multiple top level folders; in that case Sublime will include the root folder in the names of the files presented because now it's required to be able to distinguish between files in the different folders:
In addition to this, note that for any given filter text you enter in a panel, Sublime remembers the full text of the item that you selected while that filter text was being used, and uses that in it's scoring to prioritize the matches the next time you search in the same panel. The next time you search with the same term, Sublime will automatically pre-select the item that you picked last time under the theory that you probably want it again.
The search terms and their matches are saved in the session file and in your project's sublime-workspace files, so as you move from window to window and project to project you're essentially training Sublime how to find the files that you want.
My advice would be to try and flip your thinking a little bit. In my opinion the power of the fuzzy matching algorithm works best when you try to find files in a more organic way than trying to replicate the path entirely.
Instead, I would throw a few characters from the name of the file that I'm trying to find first, and then add another term that filters on some part of the path that will disambiguate things more; a term of idx s1 in this example immediately finds the two index.js files that are contained in structure1 folders, for example.
In a more real world example the names of the folders might contain the names of the components that they're a part of or something else that is providing a logical structure to the code, so you might do idx con to pull the index.js from the controller folder or idx mod to find the one in the model folder, and so on.
Regarding a better/faster way to do this I don't think there is one, at least in the general case. Sublime inherently knows every file that's in your project as a part of indexing all of the files to power other features such as Goto Symbol and it uses file watchers to detect changes to the structure of the open folders.
Anything else, including a third party plugin or package, would need to first do a redundant file scan to accumulate the list of files and would also have to replicate the file watching that Sublime is already doing in order to know when things change.

Delimiting quick-open path with fullstops in Sublime Text 3?

I'm making the move to ST3, and I'm having some trouble. I'd like to be able to delimit the quick-open filepath (⌘ + T) with periods instead of slashes or spaces. However, I can't find the setting to do that.
For example:
component.biz_site_promotions.presentation
should be able to open the file that
component biz_site_promotions presentation
would.
Any help would be greatly appreciated!
There is no setting in Sublime that changes the way this works; the search term is always used to directly match the text in the list items (except for space characters).
Note however that the Goto Anything panel uses fuzzy matching on the text that you're entering, so in many cases trying to enter an entire file name is more time consuming anyway.
As an example, to find the file you're mentioning, you could try entering the text cbspp, which in this case is the first letters of all of the parts of the file name in question.
As you add to the search term, the file list immediately filters down to text that matches what you entered; first only filenames that contain a C, then only filenames that contain a C that is followed somewhere after by a B, and so on.
Depending on the complexity and number of files that you have in your project, you may need to add in a few extra characters to dial in better (e.g. comb_s_pp). Usually this search method will either end you up at the exact file you want, or filter the list so much that the file that you want will be easier to find and select.
Additionally, when you select an item and there was more than one possible match, Sublime remembers which item you selected for that particular search term and brings it to the top of the search results next time you do it, under the assumption that you want the same thing again.
As you use Sublime more (and with different projects) you will quickly get a handle on what partial search terms work the best for you.
In addition to finding files, you can do other things with that panel as well, such as jumping to a specific line and/or column or searching inside the file for a search term and jumping directly to it. This applies not only to the current file but also the one that you're about to open.
For more complete details, there is a page in the Unofficial Documentation that covers File Navigation with Goto Anything
As an extra aside, starting with Sublime Text build 3154, the fuzzy searching algorithm handles spaces differently than previous builds.
Historically, spaces in the search term are essentially ignored and the entire input is treated as one search term to be matched character by character.
Starting in build 3154, spaces are handled by splitting up a single search term into multiple search terms, which are applied one after the other.
This allows multiple search terms to hit out of order. For example, index doc in build 3154 will find doc/index.html, but it won't find it in previous versions because the terms aren't in the right order.
As such, assuming you're not currently using such a build (as of right now it's a development build, so only licensed users have access to it), moving forward if you continue to search the way you're searching in your question, you might start getting more results than you expected.

Sublime text multiple cursors?

Sublime Text is so damn advanced and this seems like such a stupid question, but...
I started writing a for loop in PHP (using SFTP), loved that it gave me a choice to auto-generate the loop. However, it enters this weird multi-cursor mode, which
1)I am not really sure how to use/exit without using the mouse;
2) it seems useless, seeing as all 3 type the same thing, even though I need to change, for example, the $i > x or $i = x.
Although Sublime does indeed support the idea of multiple cursors (which is an incredible time saver and useful as all get out, as we're about to see), what you're actually asking about here is a snippet which in this case happens to also include multiple cursors.
The general idea is that for code that you're likely to type many times (e.g. a for loop), you can create a snippet that will generate the bulk of the text for you in one shot, and then allow you to easily customize it as needed. In this case, the snippet in question is part of the default functionality of Sublime and is provided by the shipped PHP package.
To answer point #2 in your question first, this is far from useless. As seen here, I enter the text for and then press Tab to expand the snippet out. The first thing to notice here is that the status line says Field 1 of 4 to tell me that I'm in a snippet and that it contains four fields.
The first field is the name of the control variable for the loop, and all of them are selected so that as I change the name, all of them change at the same time because when there are multiple cursors, the text you type appears at all of them at the same time.
Once I'm done changing the name of the variable, I press Tab again to go to the next field, which allows me to easily change the point at which the loop starts. Another press of Tab takes me to the third field, where I can specify where the loop ends.
One last press of Tab exits the snippet and selects the text in the loop, so I can start writing my code (caveat: I am not a PHP developer).
At this point you can see Sublime offering another snippet for echo, which would expand out to an echo statement complete with quotes, then allow me to edit the text in the echo and skip to the end.
Circling back around to the first point in your question, you can use Esc at any point to jump out of a snippet and go back to regular editing. You can also use Tab or Shift+Tab to move through the fields in the snippet, and pressing Tab at the last field in the snippet exits it as well.
In this particular case, the first field in the snippet sets up multiple cursors, and so exiting the snippet while this field is active leaves multiple cursors in effect. You can jump back to a single cursor by pressing Esc one more time (this is true regardless of how you ended up with multiple cursors).

Resources