When scrolling down in VSCode. Using arrow keys makes you have the cursor on the bottom. I can use Ctrl + Arrow Down This scrolls the screen and the cursor keeps its position. In this case I need to click on the new line in order to start editing. However I'm looking for a way to scroll and move the cursor. For example if I'm in the middle of the screen I want to scroll and get the cursor to maintain its relative position in the middle.
Has anyone done this?
With the help of the extension Multi Command
Add this setting
"multiCommand.commands": [
{
"command": "multiCommand.up1LineKeepCursor",
"sequence": [
{"command": "editorScroll", "args": {"to": "up", "by": "line" }},
"cursorUp"
]
},
{
"command": "multiCommand.down1LineKeepCursor",
"sequence": [
{"command": "editorScroll", "args": {"to": "down", "by": "line" }},
"cursorDown"
]
}
]
And these keybindings
{
"key": "shift+ctrl+alt+up",
"command": "multiCommand.up1LineKeepCursor",
"when": "editorTextFocus"
},
{
"key": "shift+ctrl+alt+down",
"command": "multiCommand.down1LineKeepCursor",
"when": "editorTextFocus"
}
You can use any key binding you like.
It works good when Word Wrap is OFF.
Related
Am new in VScode and i added a new shortcut to move the cursor right, as the right arrow key, forces me to move my hand, NOW THE RIGHT ARROW IS DISABLED and i can do other tasks such moving a full word right as the shortcut has completely replaced the right arrow key,
can someone tell me an easy shortcut to move the cursor to the right without the right arrow after each line of code, such as print(" hello world")cursor here
or tell me how to make both my custom shortcut sequence and the right arrow key work
also i noticed that the default keybinding (shift+alt+i) to move the cursor to the end of the line never worked.
thank you in advance
i found a similar post here: Visual Studio Code - multiple keyboard shortcuts?
and I've fixed moving right, but i can't do the same with the arrow up, no matter what keybinding i set,also would be nice to be able to add such moving shortcuts without having to affect the current right setting
**here is my current code on the keybiding.jsonfile - could anyone suggest a fix on this code without disrupting the current settings? **
{
"key": "shift+alt+i",
"command": "-editor.action.insertCursorAtEndOfEachLineSelected",
"when": "editorTextFocus"
},
{
"key": "shift+alt+r",
"command": "cursorRight",
"when": "textInputFocus"
},
{`enter code here`
"key": "Right",
"command": "cursorRight"
}
{
"key": "Left",
"command": "cursorLeft"
}
{
"key": "right",
"command": "-cursorRight",
"when": "textInputFocus"
},
{
"key": "shift+alt+l",
"command": "cursorLeft",
"when": "textInputFocus"
},
{
"key": "left",
"command": "-cursorLeft",
"when": "textInputFocus"
}
I've deleted all the commands and replaced them with this all seems to work enter code here
{
"key": "alt+r",
"command": "cursorRight",
"when": "textInputFocus"
},
{
"key": "Right",
"command": "cursorRight"
},
// down
{
"key": "alt+d",
"command": "cursorDown"
},
// UP
{
"key": "alt+u",
"command": "cursorUp"
},
// LEFT
{
"key": "alt+l",
"command": "cursorLeft",
},
{
"key": "Left",
"command": "cursorLeft"
},
Note: I have searched in Google and other SO posts, but none of them have helped me.
I know that we can move up or down with Alt+Arrow. Is there a way to move, let's say 25 lines up, at once? I don't want to press Alt+↑ 25 times.
Is there a plugin or a built-in feature to do this?
The reason I'm asking is that it's easier to move multiple lines at once due to the relative line numbers feature in VS Code.
I don't want to specify each number in keybindings.json (As seen here).
To make it easier to navigate the cursor in blocks of lines you could set a keybinding to jump 10 lines up or down at once (in your keybindings.json):
{
"key": "ctrl+up", // whatever keybinding you want
"command": "cursorMove",
"args": {
"to": "up",
"by": "line",
"value": 10 // change this if you want
},
"when": "editorTextFocus"
},
{
"key": "ctrl+down", // whatever keybinding you want
"command": "cursorMove",
"args": {
"to": "down",
"by": "line",
"value": 10 // change
},
"when": "editorTextFocus"
}
As noted in the comments, this comes from https://stackoverflow.com/a/48568520/836330 so upvote that.
You can use multi-command
Like in Photoshop when you move something Arrow moves 1 pixel, Shift+Arrow moves 20 pixels.
The Arrow key has no modifier combo unused so we have to choose a different key.
New keybindings to move up or down 10 lines
{
"key": "alt+numpad8", // or any other key combo
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction"
]
},
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "alt+numpad2",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction"
]
},
"when": "editorTextFocus && !editorReadonly"
}
Maybe you have to add a little delay
"args": {
"interval": 50,
"sequence": [
I do not think there is an option to achieve what you want with VS Code only but there is an extremely powerful Vim plugin which is based on Vim terminal text editor. You should check it out, you can do anything you imagine with it but it takes some time to get used to it.
https://marketplace.visualstudio.com/items?itemName=vscodevim.vim
I'm looking for something that basically combines cmd+B (show/hide sidebar) and cmd+J (show/hide terminal).
I've tried searching around but everything seems like there's only one per. Thanks!
[ I assume you know about zen mode but are looking for something different. ]
I think the easiest way to do this is with a macro extension, here using multi-command.
Put this into your keybindings.json:
{
"key": "alt+u", // whatever keybinding you want
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.maximizeEditor",
"workbench.action.closePanel"
]
},
"when": "panelVisible && sideBarVisible"
},
{
"key": "alt+u",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.toggleSidebarVisibility",
"workbench.action.togglePanel",
"workbench.action.focusActiveEditorGroup"
]
},
"when": "!panelVisible && !sideBarVisible"
},
{
"key": "alt+u",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.toggleSidebarVisibility",
]
},
"when": "!panelVisible && sideBarVisible"
},
{
"key": "alt+u",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.togglePanel",
"workbench.action.focusActiveEditorGroup"
]
},
"when": "panelVisible && !sideBarVisible"
}
I made it, by using the when clauses, to be a toggle. So the same keybinding would close both the sideBar and Panel if they are open or open them both if they are both closed.
Then I added the last two cases where one or the other of the sideBar or Panel is closed but not both. You may not care about those two cases.
By the way, this will maximize the current editor group if there are multiple groups.
I am vim user, I don't like mouse to scroll.
pagedown and pageup is not perfect for me, I want to bindkey for pageup and pagedown with 10 lines scroll or something like that
Any idea how to do this?
You can use the editorScroll command to scroll the editor any amount you set without moving the cursor from its original position. For example, in keybindings.json:
{
"key": "alt+m", // whatever keybinding you like
"command": "editorScroll",
"args": {
"by": "line",
"to": "down",
// "revealCursor": false, // set to true if you did want to move the cursor
// false is the default
"value": 10
},
"when": "editorFocus"
},
{
"key": "shift+alt+m", // whatever keybinding you like
"command": "editorScroll",
"args": {
"by": "line",
"to": "up",
// "revealCursor": false,
"value": 10
},
"when": "editorFocus"
},
complex commands including editorScroll
How can I keep the text cursor (caret) on the screen when scrolling in VS Code with Ctrl + up/down?
I've searched for scroll options, text options, extensions, etc. To no avail.
This is what I'm using in keybindings.json and it pretty much matches Visual Studio's Ctrl+Up/Down behaviour. (ie: basically SebastianDB's answer but for both keys and line up/down instead of page. Also, you don't need the macros extension, it works out of the box).
{
"key": "ctrl+up",
"command": "editorScroll",
"args": {
"to": "up",
"by": "line",
"revealCursor": true
},
"when": "editorTextFocus"
},
{
"key": "ctrl+down",
"command": "editorScroll",
"args": {
"to": "down",
"by": "line",
"revealCursor": true
},
"when": "editorTextFocus"
}
I haven't tried this myself but have you looked at this yet?
Install this:
https://marketplace.visualstudio.com/items?itemName=geddski.macros
then add a macro to ctrl+up/down with this sample and change the key from alt+pageup to what you want.
https://github.com/Microsoft/vscode/issues/22796
{
"key": "alt+pageup",
"command": "editorScroll",
"args": {
"to": "up",
"by": "page",
"revealCursor": true
},
"when": "editorTextFocus"
}
Hope it works, have a good one!
Maybe you are looking for something similar like scrolloff in vim?
Then add this to you settings.json:
"editor.cursorSurroundingLines": 9999,