27

我正在使用 Sublime Text 中的“查找全部”功能,我想从查找结果中再看到几行。我找不到这个设置——有什么办法吗?

4

3 回答 3

26

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.

于 2013-05-07T17:03:32.863 回答
11
于 2012-12-31T06:30:47.663 回答
8

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)

于 2017-03-01T17:19:54.487 回答