SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

Incremental Search

SharpDevelop 2.1 now supports incremental searching. For those of you who have used Visual Studio, the incremental search works in a similar way. First you enter incremental search mode, then type in the search text. As you type in each character the document is searched from the current cursor position and the first match it finds is highlighted.

Features

  • Ctrl+E enables incremental searching. The search will start from the current cursor position and move down the document.
  • Ctrl+Shift+E enables reverse incremental searching. The search will start from the current position and move up the document
  • As each character is typed in the corresponding matching text is highlighted in the document.
  • Any text selected before the incremental search is start will become the first part of the searched for text.
  • If the string is not found an error message is displayed in the status bar.
  • Pressing the Backspace key removes the last character from the search string.
  • Pressing the Escape or Enter key stops the incremental search.
  • If the search text contains only lower case characters the search will be case insensitive.
  • If the search text contains an upper case character then the search is case sensitive.

Searching Incrementally

Position the cursor at the location where you want the search to start from.

Enable the incremental search either by selecting the Incremental Search from the Search menu or by using the keyboard shortcut Ctrl+E.

Incremental search menu item

The mouse cursor over the text editor will then be changed to the Incremental Search icon Incremental search cursor to indicate that you have enabled the search.

The status bar text will change to "Incremental Search".

Incremental search enabled in text editor

Type in a character and the first match below the current cursor position will be highlighted. The search text is also displayed in the status bar.

Incremental search matching first character

As you type in characters the search text is changed and matching text is highlighted. If the search text cannot be found the status bar text will show an error message.

Search text not found

The search is case insensitive if all the characters of the search text are lower case. If any character is upper case then the search will be case sensitive.

If the first character typed in does not match anything below the cursor but can be found above the cursor position, at the start of the document, then the match will be highlighted and the status bar will show a warning message informing you that the end of the document has been passed. In the screenshot below the cursor was put at the end of the document and then the incremental search was started.

Passed end of document warning message

To stop the incremental search press the Escape or Enter key.

Reverse Incremental Search

The reverse incremental search will search from the current cursor position to the start of the document.

Enable the reverse incremental search either by selecting the Reverse Incremental Search from the Search menu or by using the keyboard shortcut Ctrl+Shift+E.

Reverse incremental search menu item

The mouse cursor will then be changed to the Reverse Incremental Search icon Reverse incremental search cursor to indicate that you have enabled the search. The status bar text will also be changed to "Reverse Incremental Search".

As you type a character the matching text will be highlighted and the search text will be shown in the status bar.

To stop searching press the Escape or Enter key.

Visual Studio Comparison

The differences between the SharpDevelop's and Visual Studio's incremental search.

FeatureSharpDevelopVisual Studio
ShortcutsCtrl+E, Ctrl+Shift+ECtrl+I, Ctrl+Shift+I
Case sensitive searchAn upper case character in the search string makes the search case sensitive.Select the Match case option in the Find dialog.
    Published Sep 09 2006, 04:11 PM by MattWard
    Filed under:

    Comments

     

    Rupepa said:

    Matt,

    I updated SD to build 1779 and I did not find incremental search feature! Is it already available?

    September 9, 2006 10:42 PM
     

    MattWard said:

    Well, it should have been, but I forgot to commit the ICSharpCode.SharpDevelop.addin file, which defines the majority of SharpDevelop's menu items, so the incremental search menu items and shortcuts were unavailable. It should be working in revision 1780. Thanks for letting me know.

    September 10, 2006 12:12 AM
     

    Rupepa said:

    Matt,

    Ok! Now it is working!

    I notice that there are at least two differences between  SD and VS implementation:

    SD: Ctrl+E/Ctrl+Shift+E shortcuts and the search is case insensitive.

    VS: Ctrl+I/Ctrl+Shift+I shortcuts and the search is case sensitive.

    Is there any special reason for that? Why did you decide to implement in a different way? Can you post some comments about this?

    Thank you!

    September 10, 2006 1:21 AM
     

    MattWard said:

    Currently the Ctrl+I shortcut is being used for Indent (Edit | Formatting | Indent), which is used to fix the indentation of your source code. I picked a shortcut that was free and where I could use the Shift key as well without any conflicts. I'd like it to be Ctrl+I and Ctrl+Shift+I so it matches Visual Studio however I need agreement from the rest of the SharpDevelop team before I do this. So the shortcuts may possibly change in the future. Actually Delphi 2006 uses Ctrl+E for its Incremental Find.

    The case sensitivity of Visual Studio's incremental search depends on the "Match case" option in the Find dialog. In SharpDevelop it's always case insensitive and not tied to this option in the Search and Replace dialog. If we decide to support case sensitive incremental searches, I am not sure I like the idea of doing it this way since the Search dialog is never used and not required for incremental searches. I can see some people wondering why their search is not finding any matches due to the Match case option being selected.

    Incremental search in other applications:

    Firefox allows you to do case sensitive searches, it has a sort of status bar that pops up at the bottom of the window, here you can click select a Match case option.

    Matlab allows does case insensitive incremental searches if you type your search string in lower case. If you use upper case characters it does a case sensitive search. This might be a good way to implement case sensitivity, or perhaps do a case sensitive search if the search string contains mixed case characters.

    Emacs has similar behaviour to Matlab, if you type in an upper case character the search is case sensitive. However Emacs also allows you to toggle the case sensitivity of the current incremental search via a keyboard shortcut.

    Eclipse and IntelliJ IDEA also do a case sensitive search if any character is a capital letter like Emacs. It also allows you to navigate to the next/previous match using the up/down keys. That might be a nice feature. However you could use Quick Find (Ctrl+F3) instead. uses the same capital letter trick to determine whether the search is case sensitive.

    So I'm nearly convinced to implement case sensitive incremental searches the Eclipse/IntelliJ/Emacs/Matlab way.

    September 10, 2006 2:24 AM
     

    Rupepa said:

    Matt,

    Thank you for your explanation! I agree with you! I don't think that the Find Dialog is a good place to set "Match case" option for Incremental Search. It is not intuitive. For sure Eclipse/IntelliJ/Emacs/Matlab way is much better.

    Thank you!

    September 10, 2006 3:41 AM
     

    MattWard said:

    Just updated the code so that you can do case sensitive incremental searches. If all the characters of the search text are lower case the search will be case insensitive. If any character is upper case the search will be case sensitive.

    September 10, 2006 1:32 PM
     

    Rupepa said:

    Matt,

    I updated SD and now Case Sensitive IS (Incremental Search) is working fine!

    I'm sorry but I have doubt:

    How to match a case sensitive text that have only lower cases? I mean, suppose I have the text below:

    myText Mytext  MyText  Mytext mytext  MYTEXT  mytext

    and I want to match only "mytext" in lower case (case sensitive). What I have to do?

    September 10, 2006 3:19 PM
     

    MattWard said:

    At the moment you cannot do this. The example you show would hopefully be fairly unusual. You could use Quick Find to move to the next match in the document. There's no reverse Quick Find so you can't go to the previous match.

    I am considering allowing you to move to the next/previous match using the down/up arrows. This would allow you to find the text in your example, at least eventually.

    Another possibility is a shortcut to toggle the case sensitivity, like Emacs. The status bar would need to tell you that you're doing a case sensitive search. I am not totally convinced this is a good way to do it. I actually think some sort way of moving to the next/previous match might be used more.

    I want to keep the UI simple and not overcomplicate it just to handle unusual special cases. If the functionality covers a large percentage of the possible searches people will do then I think that is good enough.

    September 10, 2006 3:56 PM
     

    Rupepa said:

    OK!

    Thank you!

    September 10, 2006 5:29 PM
     

    DavidAlpert said:

    VIM offers incremental search via '/' and allows movetonextmatch via 'n', previous match via 'N'.

    I recognize #d incremental search is not VI emulation, but thought i'd toss this out for the idea.

    perhaps, however, some similar (configurable via addin, pls?) key combination could take effect until ESC / ENTER is pressed, mutch like code-completion usurps up/down arrows.

    configurable shortcuts helps pave the way towards VI emulation...

    September 26, 2006 4:11 AM
     

    MattWard said:

    I was planning on using the up/down arrows to move to the next/previous match, similar to Eclipse. It should be fairly trivial to define the actual keys used in the .addin file. I think the majority, if not all, of the keyboard shortcuts for SharpDevelop are defined in the various .addin files. So you can certainly modify these, at least by hand.

    Hopefully at some point SharpDevelop will allow the user to redefine all the keyboard shortcuts from inside the IDE itself. Support for chorded keyboard shortcuts (e.g. Ctrl+W, E) is a separate problem which would need to be addressed.

    September 26, 2006 6:39 PM
     

    Matt Ward said:

    Here is the list of features that have been added to SharpDevelop 2.1. Feature Description Code Analysis

    March 5, 2007 7:28 PM
    Powered by Community Server (Commercial Edition), by Telligent Systems
    Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.