Searching and Replacing Text. Source Dynamics Source Insight 4.0
Reklama
Reklama
Searching and Replacing Text
Searching and Replacing Text
Source Insight provides a number of searching commands, and replacement commands that operate on the current file as well as across multiple files. When searching multiple files, source links can be used to quickly link matches.
Searching is an important activity for programmers. As such, Source Insight devotes a lot technology to help you navigate large code projects quickly. This is one of Source Insight’s important strengths.
Searching for Symbol References
To quickly search the current project for references to the currently selected symbol, use the Lookup Refer-
ences
command (Ctrl+/). See “Lookup References” on page 248. For example, click inside an identifier such
as "BeginPaint", then invoke the Lookup References command. Source Insight will open a Search Results window, which lists all the places you used BeginPaint in your project. Each matching line listed in the Search
Results window will also have a source link to the location of each line containing the word you looked up.
The Lookup References command is context sensitive, so that if finds only the correctly matching references, given the scoping context.
The Lookup References command and the Relation Window use a special search index for speed.
Relation Window Shows References Automatically
The Relation Window also shows references to the symbol at the cursor position automatically. You don’t need to use the Lookup References command unless you want to put the results into the Search Results win-
dow. See “Relation Window” on page 91.
Automatically Highlighting References in the Code
You can have Source Insight automatically highlight references to the symbol at the cursor position within the source code window. This is controlled by on a per-file-type basis using an option in Options > File Type
Options
. See “File Type Options” on page 207.
Searching the Current File
The Search command (Alt+F) searches the current file for a search pattern. The search can be forward or backwards. In addition, the search can be batch style, where the search output results are placed in a Search
Results window. See “Search” on page 314.
The Search Forward (F4) command repeats the last search, allowing you to advance through the file, finding each occurrence of a pattern.
The Search Forward for Selection command searches for the next occurrence of the first word in the current selection.
File Search Bar
The File Search Bar is used to search within the current file. To show it, select View > File Search Bar. Alternatively, you can use Activate Search Bar (Alt+Shift+F) to activate it so you can start typing into it.
To set options, click the Options button. See “File Search Bar Options” on page 206.
102 Source Insight 4 User Guide
Searching and Replacing Text
Searching Multiple Files
specify what files you want to search. The results of the search are placed in the Search Results window. The search results also contain hidden information called source links.
If you are just looking for single, whole-word references across your whole project, the Lookup References
command is much faster. See “Lookup References” on page 248.
Searching a Project
The Search Project command searches for text or keywords across all project files. This command works the same as the Lookup References command. The only difference is that each dialog box has its own persistent state.
Project Search Bar
The project search bar is used for searching across the whole project. It is a powerful way to perform a keyword based search to find name or word fragments within a given number of lines of context. To show it, select View > Project Search Bar.
See “Search Project” on page 319.
Searching for Keywords
If you want to search your whole project as though it was a web site, then use the Search Project command.
Using keyword searching, you can find any combination of terms or symbol name fragments that occur
within a specified number of lines of context. See “Search Project” on page 319.
Searching the Web
The Search Web command (Ctrl+Alt+W) searches for the identifier at the cursor position using your web
browser and your preferred web search engine. See “Search Web” on page 322.
Replacing Text
These are the methods for replacing or renaming identifiers in the current file or multiple files.
Replacing in the Current File
The Replace command searches the current file for a search pattern, and replaces the pattern with a new pat-
Replacing in Multiple Files
The Replace Files command is similar to the Replace command, except you can specify what files you want to
do the replaces in. See “Replace Files” on page 305.
If you want to rename a symbol across multiple files, the Smart Rename command is usually better, because
it is context sensitive. See “Smart Rename” on page 326.
Source Insight 4 User Guide 103
Searching and Replacing Text
Renaming an Identifier
Use Smart Rename to perform context-sensitive renaming of symbols - global or local.
To rename an identifier across all project files using a smart context-sensitive method, use the Smart
Rename
command (Ctrl+Single-Quote). Smart Rename is a context-sensitive form of a global Search and
the easiest way to replace a single word identifier with a new string. In addition, you can have Source Insight produce a log of replacements in the Search Results window. Each replacement line is listed, along with a source link to the location of each line that was changed.
Smart Rename
is also excellent for renaming local scope variables.
Search Results Window
The Search Results window is created whenever you use a search feature that searches across multiple files, such as the Search Project, Search Files, or Lookup References commands. Each line in the Search Results window corresponds to a match in some file at some line number. Matches listed in the Search Results window contain source links, which are hypertext-like links to the locations where the matches were found.
The Search Results is a text file buffer that you can also edit.
Navigation Using Source Links
Source Links connect two locations in two different text files. They connect a line of text in a "link source" file to a location in a "link target" file. Links are associated with individual lines.
104 Source Insight 4 User Guide
Searching and Replacing Text
To traverse a link, use the Jump To Link command (Ctrl+L), which takes you to the other end of the source link at the current line. A link can be traversed as long as the link source file is open. If the link target file is not open, the Jump To Link command will open the file automatically.
Figure 3.14 The Search Results window has a source link on each listed match. Each source link corresponds to a location in a file at some line number. The window above the Search Results is the target location of one of the source links.
Source Links are bi-directional, so you can use the Jump To Link command to go from the link source to the target, or from the target back to the source.
In addition, the link information is maintained as you edit your files, just as bookmarks are. A link is only removed if you delete its link source line, or close the link source file.
Searching and Source Links
The search results placed in the Search Results window by the Search, Search Files, and Lookup References commands contain Source Links. The link source file is the Search Results temporary file, and the link target for each link is the location of the matching patterns in the various files that were searched.
Source links are part of the current workspace, which means it is part of the session state. If you save the
Search Results to a new file name, the Source links will be retained in the current workspace. For example, you could search for one pattern, save the Search Results to S1.OUT, do a second search, and both S1.OUT and Search Results will have their source links. If you close the Search Results window, the source links are deleted.
Source Insight 4 User Guide 105
Searching and Replacing Text
Creating Source Links
The Parse Source Links command creates source links in the current file. You specify a search pattern which is used to parse file names and line numbers from a file. Each time a pattern matches, a new source link is inserted into the current file.
The Parse Source Links command is useful if you have a "log" or "output" file that contains compiler output and error messages. You just open the log file, and run the Parse Source Links command. A link will be setup for each line in the log file containing an error message.
Source Links from Custom Command Output
You can create source links from the output of a custom command. When defining the custom command, the
"Parse Source Links" option should be on in Custom Command dialog. You must specify a search pattern to be used to parse file names and line numbers. When the command terminates, Source Insight automatically invokes the Go To First Link command.
This is the recommended way to invoke a compiler or build tool from Source Insight. This runs the compiler, and Source Insight will position you to at each erroneous source line.
Source Link Commands
Source Insight provides the following commands for moving between link locations.
Command
Jump To Link
Go To First Link
Go To Next Link
Go To Previous Link
Table 3.6: Source Link Commands
Key
Ctrl+L
Ctrl+Shift+L
Shift+F9
Shift+F8
Description
Moves to the other end of the source link at the current line.
Selects the first link line in the link source file, and selects the associated link line in the link target file, and ensures both files are visible on the screen in windows.
Same as above, except with the next link in the link source file.
Jumps to the previous link in the source file.
Search Results Text
Each set of matches in the Search Results window has a search heading that lists the pattern that was used to search, followed by a match count. The search headings are parsed by Source Insight and each search pattern appears in the symbol window on the left side of the Search Results window to provide an overview.
For example, a typical search heading might look like:
---- GetStockObject (23) ----meaning that 23 occurrences where found.
The Search Results window is actually just another file buffer that you can edit. You may freely delete lines from the window to trim down the results. The Search Results buffer is automatically saved when you exit
Source Insight.
106 Source Insight 4 User Guide
Atsisiųsti
Reklama