Eclipse Content Assist for viewing block declarations from the closing brace? - eclipse

I'm really curious if anyone knows if Eclipse's Content Assist can be configured to display a code block's declaration by hovering over the block's closing brace (or something similar).
Rather than having to mark long code blocks with a comment, I would much rather hover over the closing brace to view which block it ends.
If what I'm saying isn't clear, imagine you had the code block below:
if (obj instanceof Double)
{
//...PROGRAM LOGIC...
}
In this example, if I were to move the caret to the end brace, right-click the end brace, or simply hover over it. A popup window would show giving me the original declaration at the top:
if (obj instanceof Double) { //...
Also, I'm interested to know if this can be done in Visual Studio; I've asked that question here.

This is nothing to do with content assist.
You can see the block of code as explained below.
Collapse all methods(By pressing Ctrl+Shift+NUM_KEYPAD_DIVIDE. Note you can expand all methods by pressing Ctrl+Shift+NUM_KEYPAD_MULTIPLY)
Hover the mouse cursor towards method collapse icon "+" as shown below.
You will see the content of the method in a popup window. Now press F2 to freez this popup and press ESC to close the popup. Scroll back and forth to see the content. Note that this works for methods, javadocs and import statements only and not for other block statements inside methods and on CLASS body.
Refer How to use Coffee-Bytes code folding for if block folding and try to check the if block content as said above.
Also you can check the scope of block statements by keeping caret after the block start("{") or block end("}") flower brackets and double clicking on it.
See below
You can expand or reduce the block selection by pressing Alt + Shift + Up Arrow and Alt + Shift + Down Arrow respectively and jump to matching bracket(Like "( or )", "{ or }") by keeping caret after the bracket and pressing Ctrl + Shift + P

You mean something like this, when hovering over the closing brace of a code block?
It seems, that this feature has already been implemented and is by default enabled - at least for org.eclipse.jdt.ui_3.9.1.v20140306-2106.
One can enable/disable this text hover (and others) by going to Window/Preferences/Java/Editor/Hovers and selecting the corresponding Source hover. By default the source hover will be activated when pressing "shift" while hovering. When the "Combined Hover" is activated, the source hover should also be automatically be activated without pressing any additional keys.
Note also, that it is quite easy to implement a custom text hover for JDT by writing a plugin and extending the org.eclipse.jdt.ui.javaEditorTextHovers extension point. As an example for how this can be done, have a look at the code of one of the default JDT hovers.

Related

How to trigger documentation popup in vscode

How to trigger a popup with documentation for identifier under the cursor?
Normally it appears when hovering the identifier using the mouse pointer:
I would like to achieve this effect using a command or keyboard shortcut.
The only related commands I found are: trigger completion (which doesn't show the function doc) and trigger parameters hint (which only works when the cursor is inside function call - parameters list).
This is the editor.action.showHover command. It is bound to cmdk cmdi by default.
Note: Shortcut works by holding down the cmd [ctrl in windows], then while holding press k then i
You can change the keyboard shortcut with a keybinding such as:
{
"key": "cmd+k ctrl+space",
"command": "editor.action.showHover",
"when": "editorTextFocus"
}
The default shortcut for Trigger Parameter Hints is Ctrl+Shift+Space
You also have, with VSCode 1.40 (Oct. 2019):
Definition Preview Hover from the keyboard
There is a new command Show Definition Preview Hover for better accessibility of the definition preview hover widget, which can be triggered by hovering a symbol with the mouse and pressing a modifier key dependent on the platform and configuration.
Previously, only the command Show Hover was provided, which is equivalent to hovering the mouse cursor over a symbol.
Now, with Show Definition Preview Hover, the detailed hover information can be shown via the keyboard.
To make this more graphic, check these steps:
In Visual Studio 2019 for Mac, I couldn't find anything about "hover" in the Key Bindings setting. The relevant command seems to be called "Show quick info" and is bound by default to Cmd + F1.
I know this question is about VSCode but I could only find this question when trying to search for an answer. Therefore I would also like to leave the information here in case somebody finds it useful.
There are multiple ways to trigger the documentation popup:
First: Using shortcut ctrl + space
Second: Using vscode extension:
Here is the documentation:
Each answer here demonstrates a different function. Below is a consolidation of every type of helpful popup, the context in which they come up and all the ways I know to trigger them.
These assume default settings.
Function: Display documentation
Shortcut: Ctrlk Ctrli
Scope: Works over named elements - variable and function names (does nothing over literals).
Can display function documentation:
or variable or even property information:
This is the same pop-up you get when you hover over the element briefly.
Function: Display parameter hints.
Shortcut: CtrlShiftSpace
Scope: Works inside a function call.
The cursor must be inside the parenthesis that contain the passed arguments. Does nothing outside that scope.
Can also be triggered by typing a comma, as if passing another argument.
Up/Down arrows can be used to cycle through overloaded definitions (instead of moving the cursor up and down the document).
Function: Display the code completion menu
Shortcut: CtrlSpace
Scope: Anywhere. Will adapt to the context. In strings will display words only. In code will offer symbol hints - function names, variable names within the current scope, known properties, etc.
Is case insensitive.
Matches all contained characters - they do not have to be consecutive (see image above).
Tab or Enter accepts the currently selected suggestion.
Symbol hints can be triggered by just typing letters. Inside strings you must use the keyboard shortcut.

Selecting block of code in Visual Studio Code

Is there a keyboard shortcut or an extension that would allow me to select a block of code?
I'd like to select everything between curly braces, between HTML tags, etc.
Use Alt + Shift + → to expand the selection between braces or tags.
Use Alt + Shift + ← to shrink the selection between braces or tags.
Here is the Microsoft Visual C++ shortcuts cheatsheet that might help you.
Update 2019/3: this inner functionality of Visual Studio is not working very well after some updates. Alt + Shift + → now selects things including braces (which annoys me).
It is not like its behavior before. It selected things between curly braces, when I first posted this answer. I'm using Mark's answer now.
If anyone has a better solution (without an extension) now, please leave a comment.
On Mac Ctrl + Shift + → to expand the selection. Press multiple times to expand to the block.
Try the expand-region extension. It currently works for JavaScript and HTML. To select ever-increasing or decreasing scope.
A quicker way is selecting a line then expanding the selection like this:
Select line Ctrl + L
Expand selection Alt + Shift + →
Doing this inside a block (HTML element, JavaScript curly braces) will select the inner block (HTML element content, inside curly braces). Do step 2 again to select block including the container (HTML element, whole function, class, etc.)
In Visual Studio Code, there is a new option called Balance. First you can place the cursor in a suitable block. After that, you can press Ctrl + Shift + P. Type balance and it lists like below.
Now press Enter, it will select the related code block like below.
For simple use, you can add a shortcut key binding.
A real working solution:
Press Command + P and search for Select to Bracket
To bind it to a key, press the little Settings icon on the right. The "Keyboard Shortcuts" Window will appear as shown in the image. Double-click on Select to Bracket and press a Keyboard shortcut you like, for example Command + Shift + H.
Now, whenever you want to select code in a block, put your cursor inside the block and press your shortcut.
It is like magic.
⌃⇧⌘← or ⌃⇧⌘→is also useful for this purpose.
A real working solution:
Search for Select to Bracket and bind it to whatever keys you like.
It is like magic.
If you are using Java in Visual Studio Code and you don't want your block selection to include the brackets (or any other peripheral character) then do the following:
Go to Visual Studio Code settings by pressing Ctrl + ,.
Search for "Java selection range" and deselect it.

How to autocomplete curly braces and move cursor into it automatically in Eclipse?

I am new into Eclipse. I found that when I type Ctrl + ( it will also generate ) automatically, and move the cursor into this pair at the same time. After I finish editing coding in the pair, the cursor will jump out the parentheses automatically when typing Ctrl + ).
It's very convenient because I don't need to take a long distance movement to operate the arrow keys with my right hand every time. I also found [] also has this functionality. Unfortunately, I still don't find any combine-keys with {} to perform this functionally. Does anyone know about it?
First, look on Eclipse jump to closing brace.
Open in Eclipse Preferences from menu Window.
Navigate on left side to Java - Editor - Typing.
There is the option {Braces} in the group Automatically close. Check this option.
Also in Preferences navigate to General - Keys.
There is in the list the command Go to Matching Bracket with Editing Java Source in column When. You can redefine the key binding of this command.

How to move out of auto-completed brackets in IntelliJ IDEA (without using the arrow keys)?

I recently switched from Eclipse to IntelliJ IDEA, and found myself wondering how to move the cursor out of a pair of auto-completed brackets.
In Eclipse after I finished typing in a pair of brackets, pressing tab brings me out of the brackets. How can I do the same thing without using the arrow keys?
Many thanks for your help!
IDEA doesn't have such feature yet. The closest equivalent is the Complete Current Statement editor action (Ctrl+Shift+Enter).
UPDATE
Initial implementation for this feature is available in 2018.2 EAP version - press Tab to jump out.
It works more like in MS Visual Studio - without visual indication of tab 'exit' position. For now, it should work in Java, SQL, Python and some other files. It will take some time for other languages to catch up - some language-specific code changes are required.
The feature is disabled by default, you can enable it in
Settings -> Editor -> General -> Smart Keys -> Jump outside closing
bracket/quote with Tab
Ctrl + Shift + Enter does not seem to work for me in IDEA 12.1.4, but I found the closest feature to what I was looking for was Shift + Enter. This completes the line, creates a new line below the current line and moves the cursor to it.
You can do this by pressing the closing symbol that you would've pressed otherwise, but was auto completed. For example, if you have just typed the f below, you would press shift and 0 (or closing parenthesis), and it will move your cursor outside of the parenthesis.
String asdf = "hello world";
System.out.println(asdf);
I went to preferences->Keymap and set a shortcut for "Move Caret to Line End" to Shift-Space. It takes me to the end of the current line I am on without adding anything, if that's what you want.
Not currently supported by Intellij. There is an open feature request on this at http://youtrack.jetbrains.com/issue/IDEA-74666. Extra votes would be nice.
Intellij supports the ctrl+shift+m shortcut that jumps to the end of the block:
https://www.jetbrains.com/help/idea/2016.2/navigating-to-braces.html
It's not quite what you're looking for, but you can type the character you are trying to move outside of (a closing paren, for example) and that should pop you outside of the auto-completed character.
Not ideal, but functional as far as I've tested it.
I set these setting:
1) I added Semicolon shortcut to Complete Current Statement:
Instead of using for loop command, I using fori command (because for command needs semicolon character):
2) I added Alt+Semicolon shortcut to Move Caret to Code Block End:
So when I inside the loop, by pressing Alt+Semicolon jumping end of the bracket, by pressing Semicolon I jumping out the bracket subsequently.
by adding these shortcuts, the speed of coding will be faster.
Such key is called "End".
You can assign any unused shortcut to "Move Caret to Line End" action in "Settings/Preferences | Keymap".
P.S. You can use Ctrl+Shift+Enter to complete your statement (in your case it will place caret at the end of line and will add ";" there) -- action called "Complete Current Statement" and shortcut can be checked/changed in a same way as described earlier.
If you decide to move back to Eclipse and use PyDev this feature by default is disabled, First Switch to PyDev Perspective and you can enable it by going under Preferences>PyDev>Editor>Typing>Enable link on Automatic parenthesis or literals closing

Go to nextline in Netbeans without using down arrow key or mouse

Imagine for example that you are writing a method inside a class:
public getFoo() {
return $this->foo;
}
So after you end typing the return value, you have the cursor after the semicolon, and in order to continue writing after the end curly brace, you have to either move the hand away to use the down arrow key, or worse, to use the mouse.
Is there a more efficient way of doing this without having to move the right hand from its natural position?
It may seem a silly question, but I have to do this all the time so I was wondering if there is a better way to do it.
you can find the list of every available shortcut and also customize them for your needs at the top menu > Tools > Options > KeyMap.
Look for "Insertion Point Down". Erm... Actually I would keep the defaults and use the down arrow after the semicolon just to move after the curly braces (semicolon is near arrows at my keyboard).
But I can suggest the following shortcuts for other situations: Ctrl + G (Go to line...), Ctrl + 7 (Navigator + Select Method if you want to go to some other method) and Ctrl + I if you want to search for something.
Just to be sure, do you know that Netbeans can generate your getter and setter methods for you? Alt+Insert, select from pop-up menu: http://netbeans.dzone.com/news/generate-constructor-getters-a.