VS Code alternative to webstorm's "find usages" - visual-studio-code

In WebStorm there's a really nice feature that you can right-click a file and choose "Find usages...", what would output all the files and all the line numbers in the project where that file is referenced (e.g. where path to it is specified as a string in JS require).
I really love that feature, since it's very useful for refactoring - before I delete or edit smth I might want to find usages first to get clear understanding of what other things would be affected.
Is there a way I could do the same thing with VS Code?
Are there alternatives to Webstorm's "Safe delete" (when deleting a file it looks for usages first and shows a warning if there're some) and rename - so if I rename e.g. foo.js to bar.js all references to it in the project (e.g. paths within require) would be automatically updated?

Unfortunately there are no built in ways to do this in VS Code and I don't know of any extensions to do this, either.

Actually you can open the helper console ( Cmd + Shift + P in mac and the shortcut is Shift + F12) and go to find all usages

Related

Visual Studio Code Ctrl + comma does not work [duplicate]

I am used to Resharper where I can search for files, not the content, but the filename, which makes it quick to open new files.
Is this feature implemented in Visual Studio Code and is there a shortcut for it?
Using Go to File... which is under the Go menu or using keyboard shortcut:
On Windows Ctrl+p or Ctrl+e
On macOS Cmd ⌘+p
On Linux Ctrl+p or Ctrl+e
Then type the file name.
Also be sure to checkout that you can set your own keybindings and that there are cheatsheets available for Windows, macOS and Linux.
Since the 1.70.0 release in July 2022, you can find and filter in tree views such as the Find Explorer. You can press Ctrl+F inside trees to pop up the Find control.
Before the 1.70.0 release
when you click anywhere in the explorer tree, and start typing something on the keyboard, the search keyword appears in the top right corner of the screen : ("module.ts")
And when you hover over the keyword with the mouse cursor, you can click on "Enable Filter on Type" to filter tree with your search !
On OSX, for me it's cmd ⌘ + p. cmd ⌘ + e just searches within the currently opened file.
Method1
Go->Go to File OR cntrl+p
Search your file
Method2
view->command palette OR cntrl+shift+p
type "Go to file"
Search your file
Win: CTRL+P or CTRL+E
Mac: CMD+P or CMD+E
Don't want to remember another shortcut?
Open the Command Palette:
Menu: View -> Command Palette
Windows Shortcut: Ctrl+Shift+P
and hit backspace to delete ">" character and then begin typing to search for files via filename. :)
Other answers don't mention this command is named workbench.action.quickOpen.
You can use this to search the Keyboard Shortcuts menu located in Preferences.
On MacOS the default keybinding is cmd ⌘ + P.
(Coming from Sublime Text, I always change this to cmd ⌘ + T)
Also works in ubuntu with Ctrl+E
You can also press F1 to open the Command Palette and then remove the > via Backspace. Now you can search for files, too.
consider you have thousand of files in vs code and you want to search for a file with particular name then
Right click VS code editor.
Select Command Palete
In the text box type the file name
The problem with Ctrl+P (or Cmd+P) is that it searches your workspace while ignoring files and folders set in the .gitignore file. To change this behavior, add "search.useIgnoreFiles": false in your settings.json file under .vscode directory.
NOTE that search.exclude and files.exclude settings will override this. So, in your settings.json file, you should comment them out or set these two settings to false as well if you want to search all the files and directories in your VS Code project. An example for settings.json where search.exclude and files.exclude are commented out for searching all the files:
{
"search.exclude": {
//"**/Lib": true,
//"**/Scripts": true
},
"files.exclude": {
//"**/Lib": true,
//"**/Scripts": true
},
"search.useIgnoreFiles": false
}
Look here for more info.
I'm using VSCode 1.12.1
OSX press : Cmd + p
If you just want to search a single file name
Just Ctrl+P, then type and choose your one
If you want to open all files whose name contains a particular string
Open search panel
Put any common words inside those files
in 'files to include', put the search string with *, e.g. *Signaller*
For filtering in the tree on keyboard typing. The feature is deprecated. No more work.
No more of this old red inflexible box:
The replacement is way better and more interesting:
Actually not really. It could have been. The new way only filters on expanded folders only. And that's a shame. Check the last session for where the development is at. And for the options we are left with.
https://code.visualstudio.com/updates/v1_70#_tree-find-control
CMD + F (mac) or CTRL + F (else) [while focused]
No settings are needed. It just works. And more elegantly (except for the problem of only filtering searching through the visible expanded directories).
And for the default mode. highlight or filter. You can change that with:
"workbench.list.defaultFindMode": "highlight"
"workbench.list.defaultFindMode": "filter"
Only the open folders and visible elements Problem and what are we at?
It's great to know about this feature. But then you'll soon encounter the limitation it has at the moment.
Filtering only through open directories. It can help great. But then we want to filter through all. And when the project is big. That becomes totally unusable.
Issues: 1, 2, 3
We can see it's added to the backlog here:
https://github.com/microsoft/vscode/issues/116286
duplicates: 1
You may think:
Expand all
Ok what about expanding all. Then using this.
===> That would work great => But => There is no such a feature of expanding all now.
Issues: 1, 2, duplicates: 1
Some configuration
At the moment no configuration does help!
"workbench.list.keyboardNavigation": "filter"
doesn't and many others. I tried them all. For the moment!
Extension that do that probably using web view
None exists. And to be implemented one needs to figure out the indexation used by vscode. Or implement its own indexation and then fuzzy search through using indexes. Otherwise something more simple that works for no big directories. Can be built fast. [I don't have time to do it myself. Especially that this would be resolved sometime in the future and we still can work with CTRL|CMD + P]
So that to clear for you the thoughts that you may get. And save you time.
Resume
So shortly we may see the feature of filtering all in a future version of vscode as it was added to the backlog. Right now we will be waiting. And maybe long enough.
Expand all seems not to be coming at any time or any time soon.
So what now. Left with nothing? Here a WORKAROUND
The now is => use CTRL|CMD + F on visible things. or on folders. By manually expanding them.
Or use CTRL|CMD + P without closing it. By following the next rules:
To open multiple files in the same editor. Navigate up and down and for each file use Right Arrow.
When they open they will be opened beside each other. You can use CMD|CTRL + ALT + LEFT | RIGHT to navigate between tabs left and right. Faster and better with the keyboard. The last open is the one you'll be at when you close the pallet.
To open a file in a new split editor use ALT + RIGHT ARROW.
Ref: 1
For windows.
if Ctrl+p doesn't always work
use Ctrl+shift+n instead.
To search for specifil file types in visual studio code.
Type ctrl+p and then search for something like *.py.
Simple and easy
If using vscodevim extension, ctrl + p won't work so I saw another answer using:
ctrl + shift + p
which opens the command palette. Hit backspace to remove the '>' and then start typing your filename.
Check your settings for 'Use Ignore Files' and 'Use Global Ignore Files'.
If these are checked, VSCode won't search any folders listed in .gitignore or .ignore
With VSCode 1.75 (Jan 2023), you will have a new file filter option: a 'Fuzzy Match' toggle.
That comes from issue 116286: Tree: Support continuous find
In a list of files I can filter them by start typing the name of the file. It is a super useful feature when you have hundreds+ files.
My issue is that the filter is trying to find the letters in the whole file name.
Here is an example search for word "file":
this-is-**file**-i-looked-for.jpeg (I expect this to be returned)
**f**or-th**i**s-**l**.jp**e**g (This should not be returned, it is only a random match)
Would it be possible to add there extra settings to only returns full strings matches? Or is there some setting already buried somewhere?
Solution: adding a 'Fuzzy Match' toggle button to the tree find widget.
New options:
defaultFindMatchTypeSettingKey.fuzzy: Use fuzzy matching when searching.
defaultFindMatchTypeSettingKey.contiguous': Use contiguous matching when searching.
I ended up installing the extension File Name Search. It displays in the side navigation bar all files that match a name part, so I can open them one by one to check them or process them.
Ctrl + p: we have to repeat the search for each file
Ctrl + f in the
explorer: it does not search, it just filters files in epanded
folders
Here is a demo of a search in explorer followed by a search in the Filename search extension:

How do I search for files in Visual Studio Code?

I am used to Resharper where I can search for files, not the content, but the filename, which makes it quick to open new files.
Is this feature implemented in Visual Studio Code and is there a shortcut for it?
Using Go to File... which is under the Go menu or using keyboard shortcut:
On Windows Ctrl+p or Ctrl+e
On macOS Cmd ⌘+p
On Linux Ctrl+p or Ctrl+e
Then type the file name.
Also be sure to checkout that you can set your own keybindings and that there are cheatsheets available for Windows, macOS and Linux.
Since the 1.70.0 release in July 2022, you can find and filter in tree views such as the Find Explorer. You can press Ctrl+F inside trees to pop up the Find control.
Before the 1.70.0 release
when you click anywhere in the explorer tree, and start typing something on the keyboard, the search keyword appears in the top right corner of the screen : ("module.ts")
And when you hover over the keyword with the mouse cursor, you can click on "Enable Filter on Type" to filter tree with your search !
On OSX, for me it's cmd ⌘ + p. cmd ⌘ + e just searches within the currently opened file.
Method1
Go->Go to File OR cntrl+p
Search your file
Method2
view->command palette OR cntrl+shift+p
type "Go to file"
Search your file
Win: CTRL+P or CTRL+E
Mac: CMD+P or CMD+E
Don't want to remember another shortcut?
Open the Command Palette:
Menu: View -> Command Palette
Windows Shortcut: Ctrl+Shift+P
and hit backspace to delete ">" character and then begin typing to search for files via filename. :)
Other answers don't mention this command is named workbench.action.quickOpen.
You can use this to search the Keyboard Shortcuts menu located in Preferences.
On MacOS the default keybinding is cmd ⌘ + P.
(Coming from Sublime Text, I always change this to cmd ⌘ + T)
Also works in ubuntu with Ctrl+E
You can also press F1 to open the Command Palette and then remove the > via Backspace. Now you can search for files, too.
consider you have thousand of files in vs code and you want to search for a file with particular name then
Right click VS code editor.
Select Command Palete
In the text box type the file name
The problem with Ctrl+P (or Cmd+P) is that it searches your workspace while ignoring files and folders set in the .gitignore file. To change this behavior, add "search.useIgnoreFiles": false in your settings.json file under .vscode directory.
NOTE that search.exclude and files.exclude settings will override this. So, in your settings.json file, you should comment them out or set these two settings to false as well if you want to search all the files and directories in your VS Code project. An example for settings.json where search.exclude and files.exclude are commented out for searching all the files:
{
"search.exclude": {
//"**/Lib": true,
//"**/Scripts": true
},
"files.exclude": {
//"**/Lib": true,
//"**/Scripts": true
},
"search.useIgnoreFiles": false
}
Look here for more info.
I'm using VSCode 1.12.1
OSX press : Cmd + p
If you just want to search a single file name
Just Ctrl+P, then type and choose your one
If you want to open all files whose name contains a particular string
Open search panel
Put any common words inside those files
in 'files to include', put the search string with *, e.g. *Signaller*
For filtering in the tree on keyboard typing. The feature is deprecated. No more work.
No more of this old red inflexible box:
The replacement is way better and more interesting:
Actually not really. It could have been. The new way only filters on expanded folders only. And that's a shame. Check the last session for where the development is at. And for the options we are left with.
https://code.visualstudio.com/updates/v1_70#_tree-find-control
CMD + F (mac) or CTRL + F (else) [while focused]
No settings are needed. It just works. And more elegantly (except for the problem of only filtering searching through the visible expanded directories).
And for the default mode. highlight or filter. You can change that with:
"workbench.list.defaultFindMode": "highlight"
"workbench.list.defaultFindMode": "filter"
Only the open folders and visible elements Problem and what are we at?
It's great to know about this feature. But then you'll soon encounter the limitation it has at the moment.
Filtering only through open directories. It can help great. But then we want to filter through all. And when the project is big. That becomes totally unusable.
Issues: 1, 2, 3
We can see it's added to the backlog here:
https://github.com/microsoft/vscode/issues/116286
duplicates: 1
You may think:
Expand all
Ok what about expanding all. Then using this.
===> That would work great => But => There is no such a feature of expanding all now.
Issues: 1, 2, duplicates: 1
Some configuration
At the moment no configuration does help!
"workbench.list.keyboardNavigation": "filter"
doesn't and many others. I tried them all. For the moment!
Extension that do that probably using web view
None exists. And to be implemented one needs to figure out the indexation used by vscode. Or implement its own indexation and then fuzzy search through using indexes. Otherwise something more simple that works for no big directories. Can be built fast. [I don't have time to do it myself. Especially that this would be resolved sometime in the future and we still can work with CTRL|CMD + P]
So that to clear for you the thoughts that you may get. And save you time.
Resume
So shortly we may see the feature of filtering all in a future version of vscode as it was added to the backlog. Right now we will be waiting. And maybe long enough.
Expand all seems not to be coming at any time or any time soon.
So what now. Left with nothing? Here a WORKAROUND
The now is => use CTRL|CMD + F on visible things. or on folders. By manually expanding them.
Or use CTRL|CMD + P without closing it. By following the next rules:
To open multiple files in the same editor. Navigate up and down and for each file use Right Arrow.
When they open they will be opened beside each other. You can use CMD|CTRL + ALT + LEFT | RIGHT to navigate between tabs left and right. Faster and better with the keyboard. The last open is the one you'll be at when you close the pallet.
To open a file in a new split editor use ALT + RIGHT ARROW.
Ref: 1
For windows.
if Ctrl+p doesn't always work
use Ctrl+shift+n instead.
To search for specifil file types in visual studio code.
Type ctrl+p and then search for something like *.py.
Simple and easy
If using vscodevim extension, ctrl + p won't work so I saw another answer using:
ctrl + shift + p
which opens the command palette. Hit backspace to remove the '>' and then start typing your filename.
Check your settings for 'Use Ignore Files' and 'Use Global Ignore Files'.
If these are checked, VSCode won't search any folders listed in .gitignore or .ignore
With VSCode 1.75 (Jan 2023), you will have a new file filter option: a 'Fuzzy Match' toggle.
That comes from issue 116286: Tree: Support continuous find
In a list of files I can filter them by start typing the name of the file. It is a super useful feature when you have hundreds+ files.
My issue is that the filter is trying to find the letters in the whole file name.
Here is an example search for word "file":
this-is-**file**-i-looked-for.jpeg (I expect this to be returned)
**f**or-th**i**s-**l**.jp**e**g (This should not be returned, it is only a random match)
Would it be possible to add there extra settings to only returns full strings matches? Or is there some setting already buried somewhere?
Solution: adding a 'Fuzzy Match' toggle button to the tree find widget.
New options:
defaultFindMatchTypeSettingKey.fuzzy: Use fuzzy matching when searching.
defaultFindMatchTypeSettingKey.contiguous': Use contiguous matching when searching.
I ended up installing the extension File Name Search. It displays in the side navigation bar all files that match a name part, so I can open them one by one to check them or process them.
Ctrl + p: we have to repeat the search for each file
Ctrl + f in the
explorer: it does not search, it just filters files in epanded
folders
Here is a demo of a search in explorer followed by a search in the Filename search extension:

The equivalent of a GUI "Quick Open" in Emacs on CLI?

The title probably doesn't describe this question well enough. Many GUI-based editors allow you to press a key combination and then start typing a file name (anywhere, in any directory) and as you're typing, a list is filtered down of all the files matching that pattern, in realtime. If you hit enter, the currently highlighted file will be opened, or if you hit the UP or DOWN arrows you can change the selection. For example, in TextMate and Sublime Text 2 (on OS X) this is achieved by hitting CMD+T.
Now I know about find-dired and find-grep in Emacs, but is there anything else available that's a little more instant? The annoying thing with dired is that you have to hit enter and perform the search in order to see if the filename was correct. This is ok if you know the filename, but not so good when you're going based on educated guesses. It seems like something emacs could be suited to. Set the directory to index (just once) then when searching filter the index using a Radix tree search or some such, using a split window to show files and responding to the UP and DOWN arrows to adjust the selection.
Anything out there? :)
ido-mode is perfect for this. It has countless useful applications, including fuzzy filename matching as you demonstrated in your picture.
Some things to get started:
What You Can Learn From ido-mode
EmacsWiki article
Introduction to Ido Mode
Anything.el does this with files and it can do much more. Here's a good introduction on how to use it.
ido-mode is great on its own, but you may find the likes of Find File In Project a better option for matching filename patterns anywhere within a directory tree.
M-x find-file-in-project RET chooses the root of the directory tree automatically (based on the directory-local variables file).
I'm just now noticing that the M-x ffip-find-file-in-dirtree RET which I also have available (and which works on arbitrary specified directory trees, irrespective of project files) is actually provided by the ffip.el included with nxhtml.
The latter also looks like it supports ido when it's enabled. (Actually, there's a bug, but change (if (memq ido-mode '(file 'both)) to (if (memq ido-mode (list 'file 'both)) in (defun ffip-find-file-in-project (file) ...)
There will doubtless be a variety of similar options available.
peepopen also provides this functionality
I found it where I didn't want to :( ...
A plugin, called "Control-P" for vim - provides the exact same functionality the author of the question is looking for.
For example - on this video - http://www.youtube.com/watch?v=YhqsjUUHj6g - go to 26:55, and there you'll find a quick and very clean example of it. So, with one command you point to the doc-root, and after that - you're good to go :) ...
Unfortunately, none of these work the same way :D ...
I've used "Sublime text 2" for a long time TOO ... and yesterday decided to try using "emacs" ("vim" is very uncomfortable). So, I wanted this functionality:
You point to the root folder of a project.
And voila - you have "quick-find" functionality.
But ... there is no such functionality :( ...
(for example - "find-file-in-project" - it requires you to set-up "a file" in the root directory of the project, so it will know that it's the root of your project ... but what if I have to work on several projects simultaneously? ... some of them - use git, some of them - SVN, and some of them - none of these ... :D ... "Sublime text" handle this situation on-the-fly ... but emacs and vim - no :( ...)
Still waiting for the answer though ...

Is there any ECB (or other)-enhanced find file mojo?

Can I use ECB (or some other project aware thing, like eproject, ibuffer, etc.) to enhance emacs's find-file goodness?
Imagine this scenario: I have several projects/directories specified in my ecb-source-path, let's call them Project1 and Project2, and they look like so:
Project1
foo.c
bar.c
Project2
foo.c
baz.c
I'd like to have find-file (or another command) work to find and jump to the files there without having to navigate to the ecb directories buffer, or have the buffers open already.
I guess my ideal usage scenario would be like so:
I'd like to C-x C-f baz (or another special command) to open Project2/baz.c. Going even further, I'd love if I could use something like ido's flex matching to get p2foo open Project2/foo.c.
¿C'est posible?
If in your example you are in project1 foo.c, and you want to get to project1 bar.c, I think most of the project tools like ede, eproject, gnu global, idutils integration etc have "jump to file" type commands. I, of course, recommend the CEDET/EDE and ECB combination. The keybinding is C-c . f which is ede-find-file.
Setting up CEDET and EDE is pretty easy, but EDE knows only a small number of different project types, and you may need to configure it for your projects by hand which is less easy.
If you want to be in project1/foo.c and jump to project2/baz.c, you just need to use locate:
M-x locate RET baz.c RET
Now select from the list.
You could use the filecache package to index the directories you want, then use ido to choose a filename from the cache. Here is one example; there are other implementations you can Google for.
Take a look at find-file-in-project. It seems to me you're looking for something similar.
I've written a package find-file-in-tags which enables you to open files in your TAGS file without specifying the path to the file. If there are multiple files that match what you've entered, you're prompted to refine your choice (or open all).
Additionally, if you have multiple work areas for the same project, find-file-in-tags uses a single TAGS file for all those work areas but opens up the file in the same work area as the buffer in which you are invoking find-file-in-tags.

What's the trick to write code faster in Eclipse?

I know there is a trick that when you type quickly code in Eclipse, you can hit some secret keys and it will auto-complete the missing parts. Who knows them?
example: I have someVeryLongVariablesWhichIWantToTypeFast and I start typing someVeryLongVa but nothing happens. Only when I type method names a yellow box appears that wants to help me.
Ctrl + Space is the autocomplete shortcut
All shortcuts you can find under Window -> Preferences -> General -> Keys
As mentioned the command is Ctrl+Space to auto complete.
You can speed it up using camelCase...so in your example:
someVeryLongVariablesWhichIWantToTypeFast
you could start typing sVL then Ctrl+Space should auto complete or list all variables that match.
CamelCase also works for specify classes, searching for classes etc.
Others I like/use:
type sysCtrl+Space to get System.out.println statement (or err)
type foreCtrl+Space after an array/list line to foreach it
Click on an argument to a method and Ctrl+1 to create a field for it and assign it, great for constructors
Ctrl+1 on any local variable to convert to field, split declaration, or inline it
if you have
object.method().method2().method3()
selecting object.method() and type Ctrl+1 to assign to a field or local variable, then you get
Object objLocal=object.method()
objLocal.method2().method3()
//Can now select objLocal.method2() and do the same again
My favourites:
Ctrl + Space - auto complete
Ctrl + 1 - show quick fix options when you are over an error / warning
Shift + Ctrl + L - list short cuts
One trick that I love in Eclipse for Java is writing backwards (meaning you write the client before the code it calls). We typically think of autocomplete to help us with methods and variables that already exist. This is okay, but even cooler is when a method/class does not exist.
Try typing this code into a method (anywhere, really):
Who who = new Who();
who.whatUpMan("hi", 32);
Now left-click on the Who at the beginning. It will give you the choice to create a class, interface, enum, etc.
Now left-click on the whatUpMan. It will prompt you to create the method with the right parameter types and everything.
These are called "Quick Fixes" in Eclipse and they give you total freedom to code from the client "backwards" to classes it utilizes. And when you've already got the method, of course, control-space and control-shift-space (to see parameters for methods) are your friends.
http://eclipse-tools.sourceforge.net/EclipseEmacsKeybindings_3_1.pdf
Some more time savers that don't seem to be mentioned:
Ctrl+3 'Quick Access' which basically let's you reach anything without clicking around too much. E.g. type 'nav' in the popup dialog, rather than Window | Show View | General | Navigator or wherever it is.
Ctrl+O 'Quick Outline': when editing Java (and some other things), pops up a lighweight dialog so that you find anything in the file by a few keystrokes
Shift+Alt+T 'Refactoring', and things below that menu - look for shortcuts there, use 'Rename', 'Move', 'Extract method', 'Change method signature' often
Alt+Up/Down move blocks of code up/down without cut/paste
Alt+Shift+Up/Down select various levels of code (expressions,statements, methods, class) easily
Ctrl+1 on the selected code offers you cool stuff eg. Extract to variable/constant/method; Split variable declaration -- see others above, or just try it on anything
Ctrl+Shift+R find any file in the workspace, similar to Ctrl+Shift+T to find types
Ctrl + Shift + O : resolve all dependances automaticall. In Java, it's a life saver as it cleans old packages and add the required one without a single line to write.
"Right click" then "refactor" : all the features are handy, but I espacially love "rename" (Ctrl + Shift + R, c.f comments) because it will apply the changes to all the project. No more tricky find / replace wit regexp to do ensure you breal nothing else :-)
"Right click" then "source" : equally useful, with a special mention to "generate getter and setter" and "implement methods"
Ctrl + D : delete a line. Kinda cool.
I kind of remember CTRL+SPACE was the shortcut for autocomplete.
Another time-saver is formatting the code automatically using Ctrl + Shift + F.
Formatter preferences http://img187.imageshack.us/img187/5866/eclipseformatter.png
General Eclipse tips
Get rid of all the crap that you'll never use
if you do web-dev ... install the database, php, pydev, modules and plugins
install svn/cvs/git plugin
use Trac
have different code enviornments for different code types, i.e. one for python-dev, c++, and so on.
wait a few weeks to months before updating
i have about 100 premade mini scripts that i use frequently.
learn to develop your own plugins, as it's easy and fun.
For some applications, the answer is to generate the code using EMF. But the EMF learning curve is significant.
I would suggest go to Eclipse -> Preferences -> General -> Editor -> Keys and to configure your own keyboard shortcuts for all common tasks so that you can have custom keybindings that are perfect for you.
Probably this might not exactly answer your question but it is very relevant to your question title.
You can define templates in Eclipse to magically type and get a bunch of code typed for you. For instance you may type something like syso or sout to get System.out.println() in your Java code.
This can be done by following Window -> Preferences -> Java -> Editor -> Templates. You can also add a Template View, which you find at Window -> Show View -> Other -> Search for Templates.
Here is an image to clarify
* Original related answer in here as well.
Hope it is helpful to someone :)