Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sublimetext2

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?

like image 889
Tim Keating Avatar asked Jul 03 '12 23:07

Tim Keating


People also ask

How do I replace multiple lines in Sublime Text?

To select multiple regions using the keyboard, select a block of text, then press Ctrl+Shift+L to split it into one selection per line. When you're done with using multiple selections, just press Ctrl+K to trim all but the first.

How do I see results in Sublime Text?

In Sublime 2, in order to call up the build results window you can use the Tools > Build Results > Show Build Results menu item.

How do I search in sublime?

Use the Search all shortcut: Ctrl + Shift + F , then select the folder in the "Where:" box below. (And for Mac, it's ⌘ + Shift + F ).

What is sublime text3?

Sublime Text 3 (ST3) is a lightweight, cross-platform code editor known for its speed, ease of use, and strong community support. It's an incredible editor right out of the box, but the real power comes from the ability to enhance its functionality using Package Control and creating custom settings.


3 Answers

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.

like image 133
dasl Avatar answered Oct 13 '22 08:10

dasl


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.

like image 25
Greg Sadetsky Avatar answered Oct 13 '22 07:10

Greg Sadetsky


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)

like image 37
rivkier Avatar answered Oct 13 '22 08:10

rivkier