Visual Studio Code Tab Key does not insert a tab

Visual Studio-Code

Visual Studio-Code Problem Overview


I'm using Visual Studio Code as my code editor. I did a search on google but wasn't able to find anything about my issue.

The issue is simple, pressing ⇥ Tab in the editor does nothing. I'm expecting it to insert 4 spaces.

Anyone know what I can do to get ⇥ Tab working like expected?

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

I had accidentally enabled a different mode for the tab key. Fixed it by pressing Cmd+Shift+M (for Mac), or Ctrl+M (for Windows).

From the Visual Studio Code Keybinding docs:

> none > | Key | Command | Command id | > | Ctrl + M | Toggle Use of Tab Key for Setting Focus | editor.action.toggleTabFocusMode | >

The current tab control mode should also show up in the status bar:

enter image description here

Solution 2 - Visual Studio-Code

To fix the issue

Pressing ctrl+M causes the ⇥ Tab key to move focus instead of inserting a ⇥ Tab character.
Turn it off by pressing the shortcut again.

To disable the shortcut
  1. Open "Keyboard Shortcuts" with ctrl+K, then ctrl+S.
    Or go to File > Preferences > Keyboard Shortcuts.
  2. Search for toggle tab key moves focus.
  3. Right Click, Remove Keybinding.

Solution 3 - Visual Studio-Code

Click "Tab Moves Focus" at the bottom right in the status bar. That's it.

I believe I had clicked on ctrl+M. When doing this, the "Tab Moves Focus" tab/button showed up at the bottom right. Clicking on that makes it go away and starts working again.

enter image description here

Solution 4 - Visual Studio-Code

Click on the explorer or any other window that is not the editor then press Ctrl + Shift (for Mac only) + M, this is the command to "Toggle Tab Key Moves Focus" on the Keyboard Shortcuts.

Solution 5 - Visual Studio-Code

In, my case I followed this advice and changed this emmet setting in vscode to false:

"emmet.triggerExpansionOnTab": false

I was receinving the error Cannot read property 'value' of null. It solved the problem immediatelly.

Solution 6 - Visual Studio-Code

Try CTR + M it will work like before.

Solution 7 - Visual Studio-Code

As of December 2018 on macOS Mojave 10.14.2 using VSCode 1.29.1 the default keybinding for 'Toggle Tab Key Moves Focus' is set to Command+Shift+M. If you got stuck with this, using that key combo should fix the issue.

Do Command+K Command+S to pull up the Hotkeys Settings and then search for Toggle Tab Key Moves Focus or editor.action.toggleTabFocusMode if you want to change the key combo.

Solution 8 - Visual Studio-Code

Had this problem. Simply press "Ctrl + M" (On Windows). Likely "CMD+M" on Mac.

Solution 9 - Visual Studio-Code

I am using code on xfce - did the following to fix the Tab key behavior:

File -> Preferences -> Settings

search for "keyboard.dispatch"

copy to right panel and change value from "code" to "keyCode"

Reload code

Solution 10 - Visual Studio-Code

All the above failed for me. But I noticed shift + ⇥ Tab worked as expected (outdenting the line).

So I looked for the "Indent Line" shortcut (which was assigned to alt + ctrl + cmd + 0 ), assigned it to tab, and now I'm happy again.


Next morning edit...

I also use tab to accept snippet suggestions, so I've set the "when" of "Indent Line" to editorTextFocus && !editorReadonly && !inSnippetMode && !suggestWidgetVisible.

Solution 11 - Visual Studio-Code

[Edit] This answer is for MSVS (the IDE, as opposed to VS Code). It seems Microsoft and Google go out of their way to choose confusing names for new products. I'll leave this answer here for now, while I (continue to) look for the equivalent stackoverflow question about MSVS. Let me know in the comments if you think I should delete it. Or better, point me to the MSVS version of this question.

I installed MSVS 2017 recently. None of the suggestions I've seen fixed the problem. The solution I figured out works for MSVS 2015 and 2017. Add a comment below if you find that it works for other versions.

Under Tools -> Options -> Text Editor -> C/C++ -> Formatting -> General, try unchecking the "Automatically indent when I type a tab" box. It seems counter intuitive, but it fixed the problem for me. enter image description here

Solution 12 - Visual Studio-Code

Maybe another program is interfering? Closing Teamviewer fixed the problem for me.

Solution 13 - Visual Studio-Code

I've had this happen before as well, where there was TeamViewer client takes the control of the TAB key. You won't know this until you close the TV window that you have open in the background.

Solution 14 - Visual Studio-Code

Make sure this is NOT checked :

[ ] Tools | Options | Text Editor | C/C++ | Formatting | Automatic Indentation On Tab

Let me know if this helped!

Solution 15 - Visual Studio-Code

For those of you not about that space bar life (- _ - )( - _ -)

  1. Keybinding for ⇥ Tab isn't set to anything so you have to do it manually

  2. Navigate to Preferences/Environment/Keybindings and search for "tab"

  3. Click on Edit Binding at the bottom and press the tab key.

  4. Press "Apply" then "Ok"

  5. Key bound!

Solution 16 - Visual Studio-Code

For some reason, after an update, my tab key was unbinded of 'tab' default behaviour. So I have to open File>Preferences>Keyboad Shortcuts, search for the simple "tab" line, and bind to the tab key again. Pretty awkward, but worked.

Solution 17 - Visual Studio-Code

On Mac,
Preferences -> settings -> Search for "tab"
Uncheck Insert spaces when pressing tab enter image description here

Solution 18 - Visual Studio-Code

Check your key mapping (File > Preferences > Key Mapping) [Ctrl+K Ctrl+S]. In the input line at the top write 'tab' and bind tab command with tab key.

It works for me. Some extension overwrite it.

Solution 19 - Visual Studio-Code

In 2022, above not working any more, Microsoft changed the key binding

On Mac, Cmd + shift + M no longer working

Instead you should use : ctrl + shift + M

Here is evidence: enter image description here

Solution 20 - Visual Studio-Code

Not sure what operating system you're on, but there was a known issue with the tab key on one of the more recent releases of VS Code for Mac OS X. The bug has been fixed in the latest release (0.10.9).

On Mac OS X, you can check for the latest update by opening VS Code and then going to [Code > Check for Updates].

Sources and more information:

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionanonView Question on Stackoverflow
Solution 1 - Visual Studio-CodepypmannetjiesView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeAddisonView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeTony L.View Answer on Stackoverflow
Solution 4 - Visual Studio-CodeAirton Gomes de LimaView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeLucas BasquerottoView Answer on Stackoverflow
Solution 6 - Visual Studio-Coderubimbura brianView Answer on Stackoverflow
Solution 7 - Visual Studio-Codeflux9998View Answer on Stackoverflow
Solution 8 - Visual Studio-CodeAlalade SamuelView Answer on Stackoverflow
Solution 9 - Visual Studio-CodeSagiView Answer on Stackoverflow
Solution 10 - Visual Studio-CodeFélix ParadisView Answer on Stackoverflow
Solution 11 - Visual Studio-CoderiderBillView Answer on Stackoverflow
Solution 12 - Visual Studio-CodeSteven DelrueView Answer on Stackoverflow
Solution 13 - Visual Studio-Codevr_driverView Answer on Stackoverflow
Solution 14 - Visual Studio-CodeArchon 808View Answer on Stackoverflow
Solution 15 - Visual Studio-CodegooseberrytoptopView Answer on Stackoverflow
Solution 16 - Visual Studio-CodeAlexandre MacedoView Answer on Stackoverflow
Solution 17 - Visual Studio-CodeKishorekumar YakkalaView Answer on Stackoverflow
Solution 18 - Visual Studio-CodeMattView Answer on Stackoverflow
Solution 19 - Visual Studio-CodehoogwView Answer on Stackoverflow
Solution 20 - Visual Studio-CodehxlntView Answer on Stackoverflow