74

When I scroll with the touch pad with two fingers in Visual Studio Code, I often scroll to the sides a little by accident. This is a bit annoying. I'd be happy to have it scroll only up and down.

Ariel Gabizon
  • 2,851
  • 2
  • 17
  • 22

11 Answers11

115

A partially satisfying solution, is to simply press Alt + z, to have the lines wrapped, and then it doesn't scroll to the side. You can also make wordWrap default as described here How do I turn on text wrapping by default in VS Code

Ariel Gabizon
  • 2,851
  • 2
  • 17
  • 22
  • 2
    If you don't want to use word wrap on long lines of code, you can use `shift+mousewheel` to scroll horizontally, or `shift+alt+mousewheel` which is faster. (This doesn't help the OP on a tablet, but I find it better on the desktop than using the horizontal scrollbar. – aamarks Jun 17 '19 at 21:18
  • Or just hit `home` twice to move to the start of the line. – aamarks Jun 17 '19 at 21:24
  • 2
    On version 1.47.3 (Mac), enabling word wrap doesn't disable horizontal scrolling. The original problem still persists. This is due to Gitlens (see other answer). – spoulson Aug 10 '20 at 19:18
  • 1
    For macOS Big Sur Version 11.5.2 `option+z` worked. – George Carvalho Sep 22 '21 at 19:59
57

If you have this problem because of Gitlens (blame lines), the solution i found is to disable gitlens.currentLine.scrollable (or set it to false in the settings json file.

TheAngularGuy
  • 939
  • 8
  • 13
21

Pressing alt + z to disable horizontal scrolling, works fine for a current single file. If you want permanent solution then for every file you visit? then follow:

Settings > Text Editor > Diff Editor > Word Wrap to on

enter image description here

Note: in case you don't know where is this Settings, just go

1. Via MENU

File > Preferences > Settings > Text Editor > Diff Editor > Word Wrap

2. Via shortcut Keys

On Windows

ctrl + , (control + comma)

On Mac - correct me if I am wrong

command + , (command + comma)

WasiF
  • 26,101
  • 16
  • 120
  • 128
9

Just want to add that some plugins, like GitLens, may mess this setting up.

E.g., with GitLens, it can add git blame information inline, at the end of each line of code, showing you who is responsible for that line's current version, and when.

Unfortunately, this information will not only be to the right of the wrap column, e.g. 80, it'll also "unlock" the horizontal scrolling, even when no GitLens blame annotation is there.

I haven't found any fix for this other than disabling such features.

DanielSmedegaardBuus
  • 977
  • 1
  • 10
  • 18
8

Just press ALT + Z -> To enable/disable the horizontal scroll

Anushil Kumar
  • 674
  • 8
  • 8
  • shortcut is used by nvdia geforce experience, do u know the exact setting of this, so that I can go manually toggle it – Time May 31 '23 at 15:25
5

⌥ + z

the shortcut for Mac. you welcome

rickandmorty
  • 165
  • 2
  • 8
3

Config: MBP 2018 | Using Magic Mouse 2.

For me, I had accidentally set the 'Scroll Beyond Last Column' to 80 chars. Just resetting it to default settings is what worked for me. Hope it does for you all!

enter image description here

Update (6th Feb, 2021): Enabling the mini-map again causes the problem. So disabled it to get rid of the issue.

iMujtaba8488
  • 241
  • 3
  • 9
1

February 2020 (version 1.43) update adds an option called: Scroll Predominant Axis

Scrolling predominant axis

When trying to scroll vertically using a modern touchpad, it oftentimes happens that the file scrolls horizontally as well. There is now a new setting, editor.scrollPredominantAxis (which is set to true by default) which blocks "diagonal" scrolling. This forces scrolling gestures to be either vertical or horizontal (based on the highest absolute scroll delta), but never diagonal.

When enabled,it prevents any diagonal scrolling.
It guesses your scrolling to either vertical scroll or horizontal scroll
.

It says by default it is enabled. If not then you can enable in Scroll Predominant Axis in settings.

Screenshot: Editor: Scroll Predominant Axis

Or in settings.json

"editor.scrollPredominantAxis": true
Eye Sight
  • 43
  • 6
0

I changed Word Wrap Column and saw scroll.

File > Preferences > Settings > Text Editor > Diff Editor > Word Wrap Column

enter image description here

Vlad Redko
  • 61
  • 1
  • 3
0

Late to the question, but because the in-VS-Code solutions were not to my liking I looked elsewhere:

If you are on a Mac with with Magic Mouse you can use BetterTouchTool to disable Horizontal Scrolling just for the Code app.

halloleo
  • 9,216
  • 13
  • 64
  • 122
-2

Use Ctrl + E, then Ctrl + W for disable horizontal scrolling.

For more details, you can refer this cite: https://developercommunity.visualstudio.com/t/disable-horizontal-scrolling-in-visual-studio-2019/612873.