IDE shortcuts - intelij IDEA to VSC - visual-studio-code

In intellij Idea, I could type "psvm" for a main method, and "fori" to get a for loop, and "sout" to get a system println, is there a way to customize intellisense in visual studio code to get the same behavior?

VSCode has many extensions that provide "snippets", shortcuts for code segments like you mentioned. The C/C++ extension which you might already have installed provides some for C++, such as main for a main method and for for a for loop. If you have the extension installed, snippets work exactly like other intellisense suggestions; you can simply type them and then press enter or tab to apply them.
You can also look for other snippet extensions by searching for #category:"Snippets" in the extension section.

Related

Visual Studio Code - Make Intellisense complete keywords from other file

quiet some time, I used Notepad++ for coding my vbs-scripts. Now I'm switching to vscode, for improved syntax highlighting and IntelliSense- features.
Some time ago, I added some "header-file" I want to include to each of my scripts, because I use the same variables in each project and am too lazy to re-type the same text over again. Is there a way to make vscode IntelliSense to recognize the variables I defined in my header-file? If so, how? I would prefer not having build my own snippets, for I still expand my "header-file".
Thank you for your help,
kind regards,
Georg
The standard method is to modify the c_cpp_properties.json, VS code can do that for you if you prefer, just when you encounter the error (squiggily line under the #include <generic_header.>) as such: include error
Mouse over the error and a pop up will show as such: error popup
(Ignore the spanish bit)
Then just use the quick fix hotkey (Ctrl + .) and vscode will do it for you.

Is there a way to turn off naming suggestions in a code snippet?

I'm writing Selenium page object classes in Java in Visual Studio Code. I created a custom code snippet that, when entered, looks more or less like this:
public WebElement ELEMENTNAME() {
return driver.findElementByCssSelector("CSSSELECTOR");
}
After I enter the snippet name and hit Tab, ELEMENTNAME gets the focus. I type the element name I've picked, such as ConfirmButton, and hit Tab...whereupon I find that my method now has the name ConfirmButtonElement, because VS Code decided to accept its own naming suggestion instead of what I typed.
How can I turn this "feature" off?
Usually VS Code's autocomplete suggestions are helpful, so I don't want to disable them entirely. But I definitely want to disable them in the case of naming things. Is there a way to do that?
(I'm not sure whether the behavior comes from VS Code itself or from an extension such as the Red Hat Java extensions.)
1. Extension to blame: It is actually happening because of Microsoft Java Extension Pack. Though it also includes the Red Hat Java Package
2. To disable this package: You can navigate to Extensions tab in VScode and search for Microsoft Java Extension Pack and click disable package.
I don't know when this may have been added to vscode, but have a look at:
// Control whether an active snippet prevents quick suggestions.
"editor.suggest.snippetsPreventQuickSuggestions": true,
true is the default, try false.

Does VS Code has any shortcut like ctrl+q in eclipse?

Does VS Code (I currently use v1.8.1) has any shortcut like ctrl+q in eclipse?
It returns your cursor to the place where you stopped writing code(very useful for fast code browsing)
and it is different to alt+left which navigate backward
EDIT: I have found that this extension should do that you're asking. I suggest trying it out.
Original:
Out of the box in VS Code, this command does not exist. The list of default shortcuts can be found here, or you can open the keybindings settings in VS Code (ctrl+k, ctrl+s on Windows) and see which commands are available.
If you'd like to suggest this as a feature, you can open a new issue on GitHub or consider creating an extension.
If I understand correctly, you want a command that will move the cursor to where the last edit in a document was made.
This should be possible using an extension that listens to document change events and records the position of the cursor. Then, when the command is issued, it sets the editors cursor to that saved position.
You can also try "Eclipse Keymap" from Alphabot Security, has a lot of eclipse bindings.
I don't believe there is a built-in way to do this, but you could work around it by using an extension such as https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks .

I've moved over to VSC from ST3, but there is no namespace auto finder/user to my knowledge, do you know of a plugin to achieve this?

I've moved over to VSC (visual studio code) from ST3, my only problem is there is no namespace auto finder/use to my knowledge, do you know of a plugin to achieve this?
For example, if I done a method like so in sublime:
public function getJob(User $user)
{
//nothing just a testmehthod
}
and I pressed f5 over the User It'd import it, or if I pressed f6 it's include the full namespace... Any plugin for VSC like this?
VS Code does have a 'quick fix'. In C# it will auto add using statements if they are missing for the statement under the cursor. The default keybinding is "ctrl+." according to the vscode documentation keybindings page.
Not sure which language you're using so I cannot test it locally. I don't know which languages it works for or if other plugins are needed to work for more languages.

Method List in Visual Studio Code

I've recently started using the Visual Studio Code editor. I'm really loving it, but there's one critical feature (for me) that I haven't been able to find. Is there a method list, similar to the Navigator in NetBeans or Member dropdown in Visual Studio?
Yes, there is the workbench.action.gotoSymbol command. On Windows and Linux it's set to CTRL+Shift+O by default, on Mac it's Cmd+Shift+O.
If this command isn't available for the file types you are working with then you should take a look at the VSCode extensions. Not all languages support this feature.
Update: As stated in the comments by #jeff-xiao this extension is Deprecated and it's now a built in feature of Visual Studio code. It should be available at the bottom of file explorer as "Outline" view.
Previous text:
There is now an Extension that supports this. Code Outline creates a panel in the "Explorer" section and for JavaScript, will list variables and functions in a file. I've been using this for a while now and it scratches the itch I had. Other commenters have mentioned it supports Python and PHP well.
It still seems to be in development but I haven't had any issues. Development version available on GitHub. If you're the author reading this - thanks!
This is how it looks:
If Code Outline is not visible, you can show it by:
Invoke Code's Go to symbol command:
macOS: cmd+shift+o (the letter o, not zero)
Windows/Linux: ctrl+shift+o
Typing a colon (:) after invoking Go to symbol will group symbols by type (classes, interfaces, methods, properties, variables). Then just scroll to the methods section.
In 2020 version of VSCode
Cmd+P
# - Find symbol across files
# - Find symbol within file
#: - Group symbols within a file
In VSCode 1.24 you can do that.
Right click on EXPLORER on the side bar and checked Outline.
There is a new release that can do that!
Check here the latest release notes regarding code outline
UPDATE: The extension features are now built-in and the extension itself is now deprecated
I have found this extention: Code Outline.
This is how it looks like:
I believe that is what you have been looking for.
There's no such feature today,
the CTRL+SHIFT+O == CTRL+P # doesn't work for all languages.
As a last resort you can use the search panel - although it is not so fast an easy to use as you'd like - you can enter this regex in the search panel to find all functions:
function\s([_A-Za-z0-9]+)\s*\(
For PHP users :)
Make sure you have 'PHP Symbol' plugin then you can get all methods and class in 'OUTLINE' Sidebar's Bottom.
Press ⌘ command + ⇧ shift + O in "macOS" or Ctrl + Shift + O while using "Windows"
OUTLINE:
#Symbol:
For python in Explorer View, click on OUTLINE as below:
Visual Studio Code market place has a very nice extension named Go To Method for navigating only methods in a code file.
Hit Ctrl+Shift+P and type the install extensions and press enter
Now type Add to method in search box of extensions market place and press enter.
Click install to install the extension.
Last step is to bind a keyboard shortcut to the command workbench.action.gotoMethod to make it a real productivity thing for a developer.
Watch this link: https://code.visualstudio.com/updates/v1_40#_type-filters-for-outline-and-breadcrumbs
Explorer -> OUTLINE, you can choose what you want to show (only methods and functions in your case) and the result is similar to Netbeans:
Open symbol by name :
CTRL+T
might be what you are looking for. Works perfectly with my TypeScript project.
It is an extra part to the answer to this question here but I thought it might be useful. As many people mentioned, Visual Studio Code has the OUTLINE part which provides the ability to browse to different function and show them on the side.
I also wanted to add that if you check the follow cursor mark, it highlights that function name in the OUTLINE view, which is very helpful in browsing and seeing which function you are in.
ctrl+shift+o // This should work for javascript files by default
For PHP install the extension PHP SYMBOLS
FOR PYTHON install the extension PYTHON
On Reload, this will work fine
in-built code OUTLINE available now with VS code
There is a plugin called show functions which lists all the function definitions in a file. It also allows you to sort the function so can search them easily.
CTRL+F12 (CMD+F12 for Mac) - opens for me all methods and members in PHP class.
For find method in all files you can press CTRL + P and then start search with #
example : #signin
Take a look at Show Functions plugin.
It can list functions, symbols, bookmarks by configurable regular expressions. Regular expressions are a real saver, expecially when you're not using a mainstream language and when CodeOutline doesn't do the job.
It's ugly to see a split window with these functions (CodeOutline seems to be better integrated) but at least there's something to use
If you are using typescript you can use this extension "Code navigator for typescript".
I have been trying it and found it useful to list my typescript class methods.