Netbeans unindent (Shift+Tab) not working when cursor is inside the line (no selection)? - netbeans

In Neatbeans, unindent works as expected when multiple lines are selected. But consider the following, where the pipe character | symbolizes the cursor position in the editor:
(a) Cursor at start of line (no selection)
|hello world!
(b) Cursor inside of line (no selection)
hell|o world!
In Netbeans, when I hit Shift+Tab on version (a) then the indentation is removed. This is what I expect.
However, when I hit Shift+Tab on version (b) then nothing happens. This is different from the code editors that I am used to. I would expect the indentation to be removed, or that the cursor moves to the start of the line, such that the next Shift+Tab will remove the indentation.
Is there a config in Netbeans that makes unindent via Shift+Tab work when the cursor is inside the line?

To shift the line to the left, regardless of the cursor position you can use the "Shift line left" editor action. In the default NetBeans mapping this is assigned to Alt+Shift+KP_LEFT and Alt+Shift-LEFT
Just open the keymap options page and search for the action "shift line"
It's not exactly what you are asking, but you could try to remap that action to "Shift-Tab" and see if it works.

TLDR: There seems to be a bug in the way NetBeans handles indenting/unindenting.
I would expect the indentation to be removed
I don't see any formal documentation on how unindenting is supposed to work in NetBeans, but it appears to move the text to the right of the cursor to the left, as long as there is only whitespace to the left of the cursor. While that is different to how unindenting works in other code editors such as Intellij IDEA and Eclipse, where the entire line is shifted to the left even when the cursor is poitioned within the text, it's not necessarily incorrect.
If you want to unindent in NetBeans there are two simple alternatives: either position the cursor at the start of the line, or select some text - anything at all! - on that line before unindenting.
Some comments in the NetBeans Bug Report Bug 212353 - Shift+Tab (Delete tab) shortcut does not work in editor may be relevant:
Please note that those actions should be inverse - I mean when you
select a block and you hit <TAB> <TAB> <Shift-TAB> <Shift-TAB> you
should always end up with the same text. The same should be true if
you change the order to <Shift-TAB> <Shift-TAB> <TAB> <TAB> you
should end up with the same text.
That said, NetBeans is not adhering to that standard. Using your second example, pressing <TAB><TAB> works fine, but subsequently pressing <SHIFT><TAB> does nothing, so it is not possible to "end up with the same text". That looks like a bug (in Apache NetBeans 11.2 at least). You can raise a bug report here.
It's also worth noting that <Shift> + <Tab> is actually defined as the keymap for "Delete TAB" rather "unindenting".
Is there a config in Netbeans that makes unindent via Shift+Tab work
when the cursor is inside the line?
I don't think so. All you can do, using Tools > Options > Keymap, is to change the shortcut keys from <Shift> + <Tab> to something else, but that won't change the behavior.

Related

VS Code: jump to next occurrence of character x

In Vim, you can press fx and Fx to move to the next and previous occurrence of x on the same line:
**fx** - jump to next occurrence of character x
**Fx** - jump to previous occurence of character x
source: https://vim.rtorr.com/
I don't wish to use a vim emulator in VS Code, I instead would like to bind Ctrl+f to forward search and Ctrl+b for backwards search.
How can I do that?
I just posted an extension (I'm pretty sure you can't do it without an extension) that does what you want: Jump and Select
It does a little more than you want in case other people would like the selection option. You can bind any keybinding to the commands you want. The following demo uses Alt+f for forward and Alt+b for backward.
Note that the key you want to go to is not displayed. And you don't have to hit Enter to trigger the move - it just goes there immediately. And it works with multiple cursors.
Also, I am not familiar with vim. If you go back to some designated previous character, should the cursor end up before or after that character? Right now it goes to that character (so the cursor is after it) but it is easy for me to make to change that behaviour in the extension. Just let me know.
In VSCode, "find next" is performed by Ctrl+G (Cmd in MacOS) and "find previous" by Ctrl+Shift+G.
You can edit the keyboard shortcuts by going to Code > Preferences > Keyboard Shortcuts and looking for both "Find Next" and "Find Previous", and hovering over the keybinding to edit it to your preference.

How can you create multiple cursors in Visual Studio Code

What are the keyboard shortcuts for creating multiple cursors in VS Code?
Press Alt and click. This works on Windows and Linux*, and it should work on Mac, too.
More multi-cursor features are now available in Visual Studio Code 0.2:
Multi cursor improvements
Ctrl+D (Cmd+D on Mac) selects next occurrence of word under cursor or of the current selection
Ctrl+K Ctrl+D moves last added cursor to next occurrence of word under cursor or of the current selection
The commands use matchCase by default. If the find widget is open, then the find widget settings (matchCase / matchWholeWord) will be used for determining the next occurrence
Ctrl+U (Cmd+U on Mac) undoes the last cursor action, so if you added a cursor too many or made a mistake, you can press Ctrl+U (Cmd+U on Mac) to go back to the previous cursor state.
Adding cursor up or down (Ctrl+Alt+Up / Ctrl+Alt+Down) (Cmd+Alt+Up / Cmd+Alt+Down on Mac) now reveals the last added cursor to make it easier to work with multiple cursors on more than 1 viewport height at a time (i.e. select 300 lines and only 80 fit in the viewport).
This makes it a lot easier to introduce multiple cursors
* Linux drag-window conflict:
Some distros (e.g. Ubuntu) assign window dragging to Alt+LeftMouse, which will conflict with VSCode.
So, recent versions of VSCode let you toggle between Alt+LeftMouse and Ctrl+LeftMouse under the Selection menu, as detailed in another answer.
Alternately, you could change your OS key bindings using gsettings as mentioned in another answer.
Multi-word (and multi-line) cursors/selection in VS Code
Multi-word:
Windows / OS X:
Ctrl+Shift+L / ⌘+Shift+L selects all instances of the current highlighted word
Ctrl+D / ⌘+D selects the next instance... and the one after that... etc.
Multi-line:
For multi-line selection, Ctrl+Alt+Down / ⌘+Alt+Shift+Down will extend your selection or cursor position to the next line. Ctrl+Right / ⌘+Right will move to the end of each line, no matter how long. To escape the multi-line selection, hit Esc.
See the VS Code keybindings (OS sensitive)
May 2017
As of version 1.13
Add multiple cursors with Ctrl / Cmd + Click
VSCode developers have introduced a new setting, editor.multiCursorModifier, to change the modifier key for applying multiple cursors to Cmd + Click on macOS and Ctrl + Click on Windows and Linux. This lets users coming from other editors such as Sublime Text or Atom continue to use the keyboard modifier they are familiar with.
The setting can be set to:
ctrl/Cmd - Maps to Ctrl on Windows and Cmd on macOS.
alt - The existing default Alt.
There's also a new menu item Use Ctrl + Click for Multi-Cursor in the Selection menu to quickly toggle this setting.
The Go To Definition and Open Link gestures will also respect this setting and adapt such that they do not conflict. For example, when the setting is ctrl/Cmd, multiple cursors can be added with Ctrl / Cmd + Click, and opening links or going to definition can be invoked with Alt +Click.
With fixing Issue #2106, it is now possible to also remove a cursor by using the same gesture on top of an existing selection.
I had problem with ALT key, fix is to change alt+click as a Gnome hotkey which clobbers multi-cursor select in VSCode, to super+click by running:
gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "<Super>"
Source: http://2buntu.com/articles/1529/visual-studio-code-comes-to-linux/
Try Ctrl+Alt+Shift+⬇ / ⬆, without mouse, or hold "alt" and click on all the lines you want.
Note: Tested on Windows.
Cmd+Option+Shift⬇ / ⬆ works for me on newest VSCode 1.29.1 and newest OSX High Sierra 10.13.6, Macbook Pro.
This adds a vertical line up/down on screen, like Option+Click/Vertical Drag does in Sublime Text.
To add multiple cursors at any points in your file, including multiple ones on the same line, do Cmd (or Option)+Click anywhere you want, shown in this video. You may also search for text (Cmd+F) that repeats multiple times, then press Option+Return to add cursors at end of EACH word.
On XFCE, go to Applications -> Settings -> Settings editor - > xfwm4 -> easy_click(disable value)
Now you can Insert Cursor with Alt + Click
I've also disabled L/R Workspace (ctrl + alt + L/R) settings in Settings -> Window manager -> Keyboard
As of Visual Studio Code version 0.10.9, you can now do a Create Multiple Cursors from Selected Lines by selecting multiple lines, and pressing Shift+Alt+I
Note: This is similar to Sublime Text's Ctrl+Shift+L functionality.
Source: https://code.visualstudio.com/updates/vJanuary#_thank-you
Relevant PR: https://github.com/Microsoft/vscode/pull/1479
On Ubuntu, in order to enable multi-cursor clicking you will need to re-assign Alt+click first, by running the command below. This is because by default Ubuntu uses the shortcut itself and has it takes precedence.
> gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "<Super>"
There is no binding for exactly what you want.
The only thing that comes close is Ctrl+F2 which will select all of them at once.
You can bind it to Ctrl+D doing the following:
Click on File > Preferences > Keyboard Shortcuts
You should see a pane full of the current bindings and on the right a list of custom bindings
In the current bindings, search for Ctrl+F2 and copy that whole line and paste it into the right pane.
You might have to remove the comma at the end and then change Ctrl+F2 to Ctrl+D and then save the file.
It should look something like this:
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+d", "command": "editor.action.changeAll",
"when": "editorTextFocus" }
]
Ctrl+Alt+⬇ / ⬆ add cursors above and below the current line. Still nowhere near as good as sublime or brackets though. I can't see anything equivalent to Ctrl+D in sublime in the keyboard shortcuts file.
https://code.visualstudio.com/Updates
New version (Visual Studio 0.3.0) support more multi cursor feature.
Multi-cursor
Here's multi-cursor improvements that we've made.
⌘D selects the word at the cursor, or the next occurrence of the current selection.
⌘K ⌘D moves the last added cursor to next occurrence of the current selection.
The two actions pick up the matchCase and matchWholeWord settings of the find widget.
⌘U undoes the last cursor action, so if you added one cursor too many or made a mistake, press ⌘U to return to the previous cursor state.
Insert cursor above (⌥⌘↑) and insert cursor below (⌥⌘↓) now reveals the last added cursor, making it easier to work with multi-cursors spanning more than one screen height (i.e., working with 300 lines while only 80 fit in the screen).
And short cut of select multi cursor change into cmd + d(it's same as Sublime Text. lol)
We can expect that next version supports more convenient feature about multi cursor ;)
Alt+Click. It works in Windows.
Details: Visual Studio Code Documentation
In my XFCE (version 4.12), it's in Settings -> Window Manager Tweaks -> Accessibility.
There's a dropdown field Key used to grab and move windows:, set this to None.
Alt + Click works now in VS Code to add more cursor.
In Visual Studio without mouse: Alt+Shift+{ Arrow }.
You can do the following per the Selection menu:
Press/hold Alt+Ctrl+Up Arrow/Alt+Ctrl+Down Arrow as required to create sufficient cursors, then Ctrl+D can be used to expand the selections.
Same issue on Ubuntu-MATE, but here you resolve it by:
gsettings set org.mate.Marco.general mouse-button-modifier "<Super>"
Alt + Command + Shift will add a cursor to the next instance of what you've selected. E.g. a variable or function name
For xfce users, just go to settings>window manager tweaks>accessibility there change the key used to grab and move windows: to super as demonstrated in the image below.
Now you can use super instead of alt. Wallah!! Go make multiple cursors by alt + click.
First go to "Keyboard Shortcuts", you can get there by hitting Cmd+k then Cmd+s, or for Windows Ctrl+k then Ctrl+s.
Once you're there, search for "Add Cursor Above" and "Add Cursor Below". You can even assign them your own key-bindings.
On windows:
CTRL+Click if you are using vscode
CTRL+Alt+Click if you are using visual studio
For Ubuntu Users
ALT + SHIFT + ⬇ / ⬆
Alt + Click works in OSX. Code Version 1.14.2

Eclipse with Emacs keybindings: rebind Ctrl+J to end line and indent?

I need to use Eclipse to edit a language that doesn't have a good major mode in Emacs. I'm using what it advertises as "Emacs keybinding scheme", but it has several distinctions, some of them just happen too often and are really annoying when they happen.
One such keybinding is the Ctrl+J, or in a more Emacs-friendly format: C-j. This combination is typically bound to insertion of new line and indentation before the caret (unlike Enter or RET, which just inserts a line ending character).
So, I went to the Preferences panel, the keys settings, but I can't find anything that would simply insert a newline character. I.e. I can unbind the C-j combination, but I don't seem to be able to assign it to do the insertion. Is there any way to do it? I only found "Insert Line (Above / Below) Current Line" command, but no analogue to self-insert-command etc.
This was one of the more important keybindings for me from emacs, so I really needed to get this to work.
Go to preferences->keys, choose emacs as the scheme, search for ctrl+j, and unbind it. It's set to incremental search by default, so I changed it to ctrl+s. Once it's unbound, it just works as it should. This has worked for me from eclipse 3.x to Juno.

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

Pydev closing parenthesis autocomplete

Is there a shortcut to jump out of closing parenthesis in PyDev/Eclipse? Having to hit arrow key to move the cursor outside of the parenthesis is kind of a pain.
As Fabio said, you can jump out by pressing TAB or Enter, but this option is turned off by default and you simply get a few spaces/a new line upon pressing TAB/Enter.
To turn this precious option on, go to:
Window > Preferences > PyDev > Editor > Typing
and check "Enable link on automatic parenthesis or literals closing".
I just type the closing parenthesis and the editor gets me out without adding extra punctuation. Some would argue that this makes the auto placement of parenthesis somewhat redundant, but I find it quite useful
In the latest PyDev (2.0), it'll now create a link when it auto-closes the parenthesis, so, after it auto-closes you can press either ')', enter or tab to go to the other side (and remember that if you want to go to the next line directly, use shift+enter.