333

I use the vim plugin and I typically scroll in vim by just holding j. In VSCode holding j just does a single j command, no matter how long it's held for.

Even in vanilla vscode this also doesn't work - problematic if you're trying to type long blocks of ########################### for comment separators. Any idea how to enable this functionality?

jjcm
  • 3,677
  • 3
  • 17
  • 14
  • 4
    Follow the steps mentioned here in the official plugin documentation. https://github.com/VSCodeVim/Vim#mac. I also did a mac restart and it worked perfectly. – Gauthaman Sahadevan Jul 27 '21 at 06:53

13 Answers13

733

To disable the Apple press and hold for VSCode only, run this command in a terminal:

defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false

Then restart VSCode.

To re-enable, run this command in a terminal:

defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool true
Steve Burns
  • 7,354
  • 1
  • 9
  • 2
  • 14
    appreciate the "not affecting things globally" version you provided. – jrrs Jun 13 '18 at 04:28
  • 7
    this does not work for me VSCode Version 1.31.1 (1.31.1), macOS 10.14.2. – Sunny Patel Feb 24 '19 at 22:22
  • 11
    Just want to chime in here if you're using the VSCode Insiders version, you should use: `defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false` – kennyvh Apr 15 '20 at 18:35
  • 10
    A useful variation is to give the `-app` flag instead of a domain, since the app name is easier to find than the domain, particularly for atypical builds of VSCode. I use the VSCodium build, so I was able to get the desired effect with `defaults write -app VSCodium ApplePressAndHoldEnabled -bool false` – Warren Young Jun 13 '20 at 11:43
  • Can you explain what the `-bool false` bit does? – jayqui Aug 04 '20 at 03:41
  • As stated in the answer, make sure you restart. Reloading the window doesn't put this into effect. – sinaza Jun 21 '21 at 20:52
  • You can't just close the window, but should actually `quit` vscode before relaunching. – Daniel Jul 13 '21 at 08:55
  • Even though the app is now called "Visual Studio Code" in Spotlight, the command above still works. – Boris Verkhovskiy Jul 14 '21 at 16:50
  • WOW, serious respect. How did you figure this out. Thank you. – quest Aug 28 '21 at 19:31
  • I had to log out and then log on again for it to work. – afarah Jul 10 '22 at 11:45
  • If you use VSCode Insiders specify `com.microsoft.VSCodeInsiders` instead of `com.microsoft.VSCode` – Ashot Vantsyan Jun 26 '23 at 07:28
83

You are on OSX, correct? If so, the issue might be Apple's "Press&Hold", where you can select alternative characters on long presses.

You can disable this "feature" with a defaults command in the terminal:

defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

You have to restart VSCode afterwards.

To reenable the previous behaviour:

defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool true
kwood
  • 9,854
  • 2
  • 28
  • 32
  • 2
    This worked for me. The functionality was working fine for me in Atom, but not vscode. Any reason why it should work in one and not the other? – Matt Mar 23 '17 at 15:00
  • 1
    You can disable it on a per application basis too, its possible that Atom ships this as default (via `defaults write com.github.atom ApplePressAndHoldEnabled -bool false` or whatever the correct domain id is) – kwood Mar 23 '17 at 19:20
61

The official vim-plugin for VS Code mentions how to set it up on macOS

defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false
defaults delete -g ApplePressAndHoldEnabled  # If necessary, reset global default
Moyuan Huang
  • 671
  • 6
  • 3
  • 8
    `defaults delete -g ApplePressAndHoldEnabled` was what I was missing. It still retains the default behavior for the other apps. – Steven Lu Mar 15 '19 at 17:30
19

The answer by Steve above didn't quite work for me because of global settings. It also left me curious about where to find the com.microsoft.VScode domain name for an app. Here is what worked for me and a generalized formulation:

To enable repeats for a specific app, like VSCode, first make sure that there isn't an overriding global setting.

defaults delete -g ApplePressAndHoldEnabled

Then enable the setting for the specific app, you can find the domain name of an app by finding it in the Info.plist document under the Contents folder where it is installed.

Example

<key>CFBundleIdentifier</key>
<string>com.microsoft.VSCode</string>

Then set the setting on the command line.

defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false

You can use this pattern other app specific settings as well. Just make sure that your settings aren't being overwritten globally.

For more information on defaults type defaults help. One more note, you don't need to run this as sudo if your user is already an admin.

Babakness
  • 2,954
  • 3
  • 17
  • 28
16

Operating System : Mac

To enable key-repeating execute the following in your Terminal and restart VS Code:

$ defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false         # For VS Code
$ defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false # For VS Code Insider
$ defaults write com.visualstudio.code.oss ApplePressAndHoldEnabled -bool false    # For VS Codium
$ defaults delete -g ApplePressAndHoldEnabled                                      # If necessary, reset global default

We also recommend increasing Key Repeat and Delay Until Repeat settings in System Preferences -> Keyboard.

this is all in our readme https://github.com/VSCodeVim/Vim/blob/master/README.md#mac-setup

Hamid Shoja
  • 3,838
  • 4
  • 30
  • 45
10

If you're on a mac and using VSCodium:

defaults write com.visualstudio.code.oss ApplePressAndHoldEnabled -bool false

Other answers targeting com.microsoft.VSCode do not work because you're not running MS VSCode. The command default write generates/updates files in ~/Library/Preferences/ appended with .plist, you have to target the right file.


My software and versions:
macOS Mojave 10.14.6
VSCodium 1.41.1
- Vim (by vscodevim) 1.12.4 with neovim enabled
Neovim 0.4.3 Vim 8.1.2250

Kyle Chesney
  • 148
  • 1
  • 9
5

If on mac, you should refer to the extension's Mac-specific instructions: https://github.com/VSCodeVim/Vim#mac

At the moment (Aug 2022), it says:

To enable key-repeating, execute the following in your Terminal, log out and back in, and then restart VS Code:


For VS Code users:

defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false

For VS Code Insider users:

defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false

For VS Codium users:

defaults write com.visualstudio.code.oss ApplePressAndHoldEnabled -bool false

For VS Codium Exploration users:

defaults write com.microsoft.VSCodeExploration ApplePressAndHoldEnabled -bool false

If necessary, reset global default:

defaults delete -g ApplePressAndHoldEnabled


We also recommend increasing Key Repeat and Delay Until Repeat settings in System Preferences -> Keyboard.

airstrike
  • 2,270
  • 1
  • 25
  • 26
mspices
  • 335
  • 2
  • 11
  • For VSCodium: defaults write com.vscodium ApplePressAndHoldEnabled -bool false https://github.com/VSCodium/vscodium/blob/master/DOCS.md – Pencilcheck Jan 25 '23 at 14:48
  • The comand from the extension install section didn't worked for me, but this worked in OS X Ventura `defaults write -app VSCodium ApplePressAndHoldEnabled -bool false` – alexventuraio Mar 07 '23 at 19:23
  • line 2 worked for me after using cmd+Q on vscode (no relogin needed). The 5th line seemed to not work. Not sure what's it's supposed to do anyway – Rivenfall Jun 16 '23 at 14:16
  • 1
    @Rivenfall the last line is to restore the default setting if necessary (see comment at the end of the line) – mspices Jun 21 '23 at 15:26
4

None of the above worked for me with my new laptop, instead I had to use:

defaults write -g ApplePressAndHoldEnabled -bool false
Weidong Fang
  • 59
  • 1
  • 3
3

The best answer from Steve doesn't work for my mac 'defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false', however below works for me:

sudo defaults write -g ApplePressAndHoldEnabled -bool false

reference: https://github.com/VSCodeVim/Vim/issues/345

NoAppleOnHead
  • 62
  • 1
  • 5
2

For those of you on VS Code Insiders, just change the Bundle identifier to:

defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false
Will
  • 1,592
  • 12
  • 22
1

If you are on Mac M1 what I had to do was run what @NoAppleOnHead said of:

sudo defaults write -g ApplePressAndHoldEnabled -bool false

Then after doing so restart your Mac and you should be good to go

syntactic
  • 109
  • 6
  • I am on M1 but I don't need to restart mac to take effect and I ran `defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false` instead since I use insider – Pencilcheck Jan 11 '23 at 13:40
0
Though I reset with above mentioned commands and even after reboot, Once I open
VSCode they are getting reset, so I had 'code' script to set them back
every time I open VSCode editor.

 $ cat code
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* &
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false
defaults delete -g ApplePressAndHoldEnabled
satyavvd
  • 39
  • 1
0

For my M1 MacBook Pro, I had to run

sudo defaults write -g ApplePressAndHoldEnabled -bool false

as noappleonhead said

Then had to restart/relogin Mac. And it started to work fine.

  • I am on M1 but I don't need to restart mac to take effect and I ran defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false instead since I use insider – Pencilcheck Jan 11 '23 at 13:40