microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.07k stars 28.8k forks source link

search ignore white spaces #70697

Closed Louis7777 closed 5 years ago

Louis7777 commented 5 years ago

I think it would be really convenient to have a search toggle that allows us to search while ignoring any whitespace.

For example, if the code contains the word Github but you search for Github , you won't get any results because of the space.

This is a feature that I liked in Dreamweaver (enabled by default for all searches) and that is missing from VS Code.

search-ignore-white-spaces

VS Code has most of the options seen above, such as Match Case, Match Whole Word and Use Regular Expressions, but it doesn't have Ignore White Spaces.

Untitled

roblourens commented 5 years ago

It seems like the easiest thing to do is to not add whitespace to your query. I don't really see the benefit of this.

Louis7777 commented 5 years ago

It seems like the easiest thing to do is to not add whitespace to your query. I don't really see the benefit of this.

@roblourens

The fact that I have not given the best of examples - in favor of simplicity - doesn't mean that there aren't benefits.

So here's another example. There are many code tutorials, snippets and fixes on the Web which require you to search and add or replace code.

Try searching for this:

if(...)
{

var hello;
}

When in reality it is like this:

if (...) {
    var hello;
}

Yeah, no luck.

There have been many occasions where I couldn't locate the suggested code (and eventually I had to be much more specific in my queries) because of whitespace differences! You name it - tabs, trailing spaces, new lines etc.

And in any case, does it matter whether I can express the benefit of it? Adobe has it in their product enabled by default. There have to be benefits, one would think, right? Plus, it is the only option missing from VS Code's search. It'd be a good thing to have it.

roblourens commented 5 years ago

This would require us to either rewrite the query into a regex that can match different things or to build an index of the codebase that we can fuzzy search. We investigated the second and rejected the idea of including fuzzy search as being too complex for a "simple/lightweight" code editor.

Louis7777 commented 5 years ago

Well, maybe someone can come up with a good implementation if we don't dismiss the idea. After all, these days VS Code is an all-in-one editor rather than a "simple" editor like Dreamweaver - yet the latter has had this neat feature for a long time.