You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 19, 2023. It is now read-only.
Fix a few typos and small problems on the code search cheat sheet page (#482)
* Fix a few typos and small problems on the page
I was just reading the page to learn about the search syntax, spotted a few problems, and decided to fix them to improve this page.
For the types, I used https://docs.sourcegraph.com/code_search/reference/queries as a source.
* Update markdown for links
Co-authored-by: ltagliaferri <[email protected]>
Copy file name to clipboardExpand all lines: posts/how-to-search-code-with-sourcegraph-a-cheat-sheet.md
+40-28Lines changed: 40 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,9 @@ type: posts
13
13
14
14
Sourcegraph is a universal code search tool, enabling you to search across both open source and your own private code repositories. Code search can help you onboard onto new codebases, contribute to open source, find bugs and error messages, understand dependency libraries, and more.
15
15
16
-
This cheat sheet style guide can help you get up to speed with Sourcegraph commands quickly. For more thorough tutorials on using Sourcegraph, refer to our tutorials(https://learn.sourcegraph.com/tags/sourcegraph) and our documentation(https://docs.sourcegraph.com/).
16
+
This cheat sheet style guide can help you get up to speed with Sourcegraph commands quickly. For more thorough tutorials on using Sourcegraph, refer to our [tutorials](https://learn.sourcegraph.com/tags/sourcegraph) and our [documentation](https://docs.sourcegraph.com/).
17
17
18
-
You can use these commands on either Sourcegraph Cloud(https://sourcegraph.com/search) or your own Sourcegraph instance(https://docs.sourcegraph.com/admin/install).
18
+
You can use these commands on either [Sourcegraph Cloud](https://sourcegraph.com/search) or your own [Sourcegraph instance](https://docs.sourcegraph.com/admin/install).
19
19
20
20
## Searching an organization’s repository
21
21
@@ -48,10 +48,10 @@ When searching a repository, command chaining can be used to return more specifi
48
48
49
49
**Search for a repository that contains a file**
50
50
51
-
If you are searching for a file in a repository, use `repo.contains.file`.
51
+
If you are searching for a file in a repository, use `repo:contains.file`.
Sometimes the time period can be literal, like `last week`, `last year`, `3 months ago`, `february 10 2021` or have actual dates in the format `dd/mm/yyyy`.
131
+
Sometimes the time period can be relative, like `last week`, `last year`, `3 months ago` or absolute, in several formats including `{month} {day} {year}` (example: `february 10 2021`), `dd/mm/yyyy`, and ISO format `yyyy-mm-dd`.
132
132
133
133
<Highlighter
134
134
input='before:last week'
@@ -158,10 +158,18 @@ Note that `before` and `after` only work in conjunction when combined with `type
158
158
The `archived` keyword will bring up those results from repositories that have been archived.
159
159
160
160
<Highlighter
161
-
input='archived:yes/only
162
-
archived:yes
163
-
archived:only'
164
-
matcher='yes/only'
161
+
input='archived:yes'
162
+
matcher='yes'
163
+
/>
164
+
165
+
<Highlighter
166
+
input='archived:no'
167
+
matcher='no'
168
+
/>
169
+
170
+
<Highlighter
171
+
input='archived:only'
172
+
matcher='only'
165
173
/>
166
174
167
175
We can surface only archived repositories within the Sourcegraph organization with the following query.
@@ -175,13 +183,16 @@ This can help us understand past decisions made within a given codebase.
175
183
Use `yes` or `no` with the `case` search query to specify if the search should be case sensitive or not. By default, searches are case insensitive.
176
184
177
185
<Highlighter
178
-
input='case:yes/no
179
-
case:yes
180
-
case:no'
181
-
matcher='yes/no'
186
+
input='case:yes'
187
+
matcher='yes'
188
+
/>
189
+
190
+
<Highlighter
191
+
input='case:no'
192
+
matcher='no'
182
193
/>
183
194
184
-
Suppose you would like to check to align the style of a given codebase to help you bring all function calls in Python to be consistent with the PEP 8(https://www.python.org/dev/peps/pep-0008/) guidance. You can use Sourcegraph to understand which functions are using camelCase rather than lowercase names with underscores between words (also called snake_case).
195
+
Suppose you would like to check to align the style of a given codebase to help you bring all function calls in Python to be consistent with the [PEP 8](https://www.python.org/dev/peps/pep-0008/) guidance. You can use Sourcegraph to understand which functions are using camelCase rather than lowercase names with underscores between words (also called snake_case).
@@ -193,20 +204,21 @@ If you would like to find all declared functions that use camelCase, you can try
193
204
Types define the scope of code search. A search scope consists of commits, diffs, symbols, repos, paths and files. It is typically used alongside other search commands to further narrow search results.
194
205
195
206
<Highlighter
196
-
input='type:commit|paths|diff|symbol|repo|files'
197
-
matcher='commit|paths|diff|symbol|repo|files'
207
+
input='type:commit|path|diff|symbol|repo|file'
208
+
matcher='commit|path|diff|symbol|repo|file'
198
209
/>
199
210
200
211
Here is an example to show us time-based commits on the Sourcegraph repo.
A `type` scope can use the following commands, which will restrict search to the following:
205
-
*`commit` — commits to a repository
206
-
*`diff` — show diffs(https://git-scm.com/docs/git-diff), or changes, within a repository
207
-
*`repo` — repositories available to you
208
-
*`files` — returns files
209
-
*`symbol` — returns files that contain names or keywords in a library.
216
+
*`commit` — commits to a repository.
217
+
*`path` — restricts terms to matching filenames only (not file contents).
218
+
*`diff` — show [diffs](https://git-scm.com/docs/git-diff), or changes, within a repository.
219
+
*`repo` — repositories available to you.
220
+
*`file` — restricts terms to matching file contents only (not filenames).
221
+
*`symbol` — returns files that contain names or keywords in a library.
210
222
211
223
Searching by type can help you find exactly what you need in a codebase by narrowing down the scope of your search.
212
224
@@ -319,8 +331,8 @@ This can allow you to search across the code that is private to only you. _Pleas
319
331
## Further resources
320
332
321
333
To learn more about how to search effectively with Sourcegraph, you can read through our Sourcegraph search series:
322
-
* How To Search with Sourcegraph using Literal Patterns(/how-to-search-code-with-sourcegraph-using-literal-patterns)
323
-
* How To Search with Sourcegraph using Regular Expression Patterns(/how-to-search-with-sourcegraph-using-regular-expression-patterns)
324
-
* How To Search with Sourcegraph using Structural Patterns(/how-to-search-with-sourcegraph-using-structural-patterns)
334
+
*[How To Search with Sourcegraph using Literal Patterns](/how-to-search-code-with-sourcegraph-using-literal-patterns)
335
+
*[How To Search with Sourcegraph using Regular Expression Patterns](/how-to-search-with-sourcegraph-using-regular-expression-patterns)
336
+
*[How To Search with Sourcegraph using Structural Patterns](/how-to-search-with-sourcegraph-using-structural-patterns)
325
337
326
-
You can also check out Sourcegraph product documentation(https://docs.sourcegraph.com/) and Sourcegraph tutorials(https://learn.sourcegraph.com/tags/sourcegraph).
338
+
You can also check out [Sourcegraph product documentation](https://docs.sourcegraph.com/) and [Sourcegraph tutorials](https://learn.sourcegraph.com/tags/sourcegraph).
0 commit comments