How to center the editor window back on the cursor in VSCode? - keyboard-shortcuts

I'm using VSCode as my text editor. I'm curious, is there a keybinding for centering the editor window on the cursor, when the window is a lot of lines below/above it such that it's not visible on the screen? I've tried looking at the default keybindings by going to FIle > Preferences > Keyboard Shortcuts, but I see no such options for centering the window.

There is no such keybinding / command built-in.
I couldn't stand that either, so I created a VSCode extension. You can find it and install it here on the marketplace. The default shortcut is CTRL + L.

If you are using vscodevim, zz should work.

If you want to always keep the cursor on the center, you can change the setting Cursor Surrounding Lines to a really high number (100 is ok) and that should work.

As #kwood put it, there is an extension Center Editor Window in the marketplace that meets this end.
I would like to make an answer here, to complement that -- even the extension's author did not explicitly state in the marketplace page -- if you would like to change the default key binding (Ctrl+L), you may try put the following lines in the keybindings.json for the keyboard bindings.
{
"key": "cmd+k cmd+c",
"command": "center-editor-window.center",
"when": "editorTextFocus"
},
The above command sets ⌘ Command+K, ⌘ Command+C as the keyboard shortcut.
Apart from that, you may set
"center-editor-window.threeStateToggle": true,
in the settings.json for VS Code settings so that it will switch among three states (center, top, bottom) instead of one (center).

Related

Is there any way to switch windows in VScode via keyboard shortcut when the focus is on the terminal?

I would like to switch between windows (vscode) regardless if the focus is on the editor or on (any) terminal. I tried the key binding below in the json file without any luck. Also, dropping the "when" clause or only using terminalFocus doesn't work. It seems I can only switch windows if the focus is on the editor. Would be grateful for any suggestions.
{
"key": "ctrl+w",
"command": "workbench.action.switchWindow",
"when": "terminalFocus || editorTextFocus"
}
In my testing I see two options:
(1) It appears that any other keybinding except Ctrl+W works as expected; or
(2) add your command workbench.action.switchWindow to the Terminal > Integrated: Commands to Skip Shell list in your settings if you want to use Ctrl+W as your keybinding.

IntellijJ: Resizing Window with keyboard

I am trying to use the keyboard shortcut Shift+Command+[Left|Right|Up|Down] to resize windows in intelliJ. But it doesn't work. Weirdly, in Window->Active Tool Window -> Resize I do see the option to apply the same options Stretch To [Left|Right|Up|Down] along with the corresponding shortcut key combination and that usually works for all windows except the editor window in which all the four options are shadowed even when the editor windows isn't stretched to it's full extent. Anyone has any idea on what is going on? I can do the resizing using the mouse.
It's because these shortcuts only work in tool windows and the editor is not a tool window. From Tool Windows:
Attached to the bottom and sides of the workspace are IntelliJ IDEA tool windows.
[...]
Within the editor, the shortcuts have different meaning:
ShiftCommand← – Move caret to line start with selection
ShiftCommand→ – Move caret to line end with selection
ShiftCommand↑ – Move statment up
ShiftCommand↓ – Move statment down
The editor doesn't have a specific size, it uses the available space. To make it larger or smaller, you have to resize the attached tool windows.

Intellij Idea - how to get rid of thick caret/cursor

I pressed something in Intellij and my caret shape changed to this. How to revert to the normal thickness? Using Intellij 2016.1.
Compare to this, normal thickness should be that of a bold vertical line:
Update: On Android Studio 2.1 beta, same machine, same font settings, cursor is visibly thinner.
You can .. but it's not pixel perfect. I mean -- for me the value does not seem to control thickness in pixels but rather some index (which gets applied to some predefined values) -- at least this is my impression on what I see my computer.
In any case:
Help | Find Action...
Search for registry action
Once in Registry window -- look for editor.caret.width entry
Set the new value (for me the default was 2) -- make sure that field went bold (move to another entry) to ensure that new value was accepted.
Restart IDE (this option requires it)
UPDATE (2017/04/06):
You may also try ThinCaret plugin:
Makes your editor caret 1 pixel thin (for retina users)
You can change it under Settings -> Editor -> General -> Appearance -> Use Block caret
Other caret settings are under Settings -> Editor -> Colors & Fonts -> General. Then if you scroll down to the editor section on the right, there is a caret item in the list with font/color settings.
Please check the Picture for solution.
If you got here because of the thick cursor (block cursor) that behaves differently than the normal thin one. Just press the insert (Ins) button once and you are good to go.
Go to the Keymaps section of the Preferences and add your own Keyboard shortcut if you are using a Mac. Windows users can just enable/disable Insert mode on their keyboard.

Cycle through autocomplete suggestions without arrows

I'm really impressed with the autocomplete feature of the IntelliJ IDE so far.
What I'd like to do, is cycle through the autocomplete suggestions I get when hitting Ctrl + Space without using the arrow keys (↑, ↓).
The reason for this is that I prefer to keep my fingers on the home row (I'm using IntelliJ's Vim emulator additionally).
For example, how would I select sortThis instead of sorted without using the arrow keys or the mouse?
Peter Gromov's answer brought me to a satisfying solution:
In IntelliJ's settings, for Keymap → Editor Actions → Down I set a custom shortcut: Ctrl + J.
This way I can cycle forward through the suggestions.
Setting a shortcut for Down with Selection or Scroll Line Down in the IdeaVim-specific shortcuts did not affect the selection of autocomplete suggestions though.
The answer here: https://stackoverflow.com/a/9713306/2370679 led me to discover that Ctrl+n & Ctrl+p allow navigation of the auto-complete options without having to modify any settings
For macOS the IDE will give a hint that "^↑ and ^↓ will move caret up and down in the editor". These clearly do not work.
There are a few extra steps that are needed after following #matthias-braun's solution.
Here is the full list of step that I use:
Go to Preferences -> Keymap
Expand Editor Actions (not Plug-ins -> IdeaVim)
Select Down
Click the pencil icon or right-click
Select Add Keyboard Shortcut
Press the shortcut (I use ^N)*
Repeat for 3-6 for Up (I use ^P)
Click Ok**
Go to Preferences -> Other Settings -> Vim Emulation
In the drop-down under the Handler column for the row containing Down, select Vim***
Do the same thing for Up
* If you are warned about the key binding already existing then remove it. You can always reset back to the defaults by clicking the little cog icon up the very top to the right of the drop-down menu.
** The Vim Emulation doesn't seem to be populated correctly until you reopen the Preferences.
*** I'm not sure why the Handler should be Vim. This seems backwards to me but it works.
If you're able to scroll up/down in editor with some IdeaVIM-specific shortcuts, they should also work in the completion list.
In this particular case, I'd just type another "t" so that "sortThis" becomes selected (and the only) variant.
I have done the same thing with mapping the arrows but in a more logical way:
I mapped them that when I press 'Alt' 'J' is left, 'L' is right, 'I' is up, and 'k' is down. that way I can have easy access to the arrows while my fingers are on the home row and I don't need to move them nearly as much...
I'm posting it just so people who search it on google can have that idea.

Intellij - what is this strange selection, and how do I turn it off?

See the screenshot below to see what I mean. Basically, Intellij only highlights the box I draw with the cursor, but leaves the rest of the editor untouched. I have no idea why it happens, and the only way to resolve it for now is to close and reopen the editor. I have observed the same behavior on a Linux box and a MacBook, both when editing Java and PHP files, so I am not sure it's a bug.
The desired behaviour is standard row selection, i.e. highlight all rows which I drag the cursor over.
I think you have enabled 'column selection'.
Option can be toggled via these methods:
Menu Bar -> Edit -> Column selection mode
Document Body -> Right Click -> Column selection mode
Keyboard Shortcut -> ALT + SHIFT + INSERT
The column select mode is enabled, use Alt+Shift+Insert to enable or disable this mode.
Shift-command-8 to toggle it back and forth on OSX.