1275

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.

What can I do to get Tab ↹ working like expected?

5
  • 151
    I had a problem where tab would just tab outside of the editor (navigating between UI elements). Restarting the editor fixed it. Commented Apr 2, 2019 at 8:48
  • 4
    Not answering op questions, but for anyone else landing here after searching "visual studio tab not working" or having issue when hitting Tab in Visual Studio selects block instead of adding indentation. You can refer to this answer by Karel Tamayo Commented Apr 10, 2019 at 14:13
  • 1
    See VS reference for Tab trapping Commented Nov 12, 2021 at 1:42
  • 2
    @AlainD The idea is probably to allow moving around in the editor without leaving the keyboard :) Commented Jan 11, 2022 at 15:24
  • @Nearoo Exactly. Some people are unable to use a mouse so it's an important accessibility feature. Commented Sep 20, 2023 at 10:03

23 Answers 23

3132

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

From the Visual Studio Code Keybinding docs:

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

The current tab control mode should also show up in the status bar. It should say Tab Moves Focus:

Sign up to request clarification or add additional context in comments.

10 Comments

Happened to me when I tried to use the code collapse (Ctrl + M, Ctrl + O). Thx.
@Jannunen you're right, sadly for us who have 25inch screens, nobody is gonna notice that teeny tiny thing in the corner...
What a truly peculiar setting. It's especially confusing because Ctrl-M is used to open up a development menu in the Android emulator (writing in React Native / Expo). I must have accidentally pressed it when VSCode was open and not the emulator. What a bewilderingly strange feature, though.
Delete the keybinding for Toggle Tab Key Moves Focus immediately so this never happens again! See answer by @Addison.
@Teekin It's not bewilderingly strange, it's to allow moving the focus (as tab does in most contexts) without touching the mouse. This might be preference for some, and is vital for others, as some people are unable to use a mouse. The feature is labelled an "Accessibility mode".
|
485

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

enter image description here

I believe I had pressed 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.

You can type Ctrl+M again to toggle it off as other answers have pointed out, but that's not as easy to remember as just clicking on it.

6 Comments

Saved me, I do not know how I enabled it but I installed a new keyboard and suddenly TAB was jumping into different windows.
Microsoft products have many rubbish built in. another famous is Multiple Desktop in Windows 10, or unable to Create Desktop Shortcut in Windows 10 . so when you try to add Shortcut for Skype App into Desktop, good luck
This should definitely be the accepted answer. I have no idea how this happened, but it was exactly my problem also. Thank you!!!
Does anyone know how I can remove this CTRL+M shortcut to something complex for "Tab Moves Focus".
Ctrl+M is unfortunately the 'Toggle Outlining' on the old PowerShell ISE. When I jump between that and VSCode I naturally hit the Ctrl+M by mistake. Most annoying.
|
354

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.

7 Comments

Thank you for this! I use ctrl + m -> ctrl + k -> ctrl + 0 to collapse code and almost daily I accidentally break my tab functionally before this :)
I just installed MSVS 2019. I don't see Preferences under the File tab. ctrl-k, ctrl-s opens a list of snippets. I don't see a "toggle tab key moves focus" option. Which version of MSVS are you using?
@riderBill - This is for the latest VS Code 1.39.2 (2019-10-15). You are using Microsoft Visual Studio, which is not to be confused with Visual Studio Code.
Oh. <:^| My mistake. But not (entirely) my fault. I'll plead "Microsoft is an industry leader in poor choices for naming new products." As is Google. Ever try to search for help on Google Messages? [Sigh]
With no obvious indication as to what's happening, what an utterly stupid UI design. Thanks for the answer. :)
|
99

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.

2 Comments

Is there any way to disable this "feature" ?
@AlexanderRyanBaggett just remove the keybinding
27

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.

1 Comment

This worked only after doing ctrl+m as well (perhaps because I had tried some of the other suggestions without success before trying this).
17

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 Cmd+Shift+M. If you got stuck with this, using that key combo should fix the issue.

Do Cmd+K Cmd+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.

1 Comment

On Windows it's just Ctrl+M by default to Toggle Tab Key Moves Focus. And Dan, that's a tad hyperbolic, considering the default in Visual Studio to format a document is actually Ctrl+K, Ctrl+D - visualstudioshortcuts.com/2017
12

This answer is for (the IDE).

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

3 Comments

Same in VS Community 2022. This is a mislabeled option. Yes, I want tab to indent, but I still want tab to work to format other parts of the line if not at the beginning. The VS2022 IDE disables tab if not used at the beginning of the line if this option is checked. Thank you!
Thanks, had this exact issue with VS2015.
I somehow managed to accidentally turn this on while exiting debug mode... No clue what i hit to trigger it. For better searchability, "Visual Studio tab stopped working except for in comments". "Visual Studio cant insert tab when pressing tab key".
10

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.


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

1 Comment

Perfect! Thank you for figuring out a functioning when condition.
9

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

  • File -> Preferences -> Settings
  • Search for "keyboard.dispatch"
  • Copy to right panel and change value from "code" to "keyCode"
  • Reload code

Comments

5

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

  1. Key binding 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!

Comments

4

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 Tab ↹ again. Pretty awkward, but worked.

Comments

4

Restarting VS Code will do the job.

1 Comment

Likely because it clears the Moves Focus setting discussed in other answers. I would only resort to doing this if none of the other answers work.
4

If your tab is not inserting space but focusing button element then following solution will work for you:

Just set a key bindings to tab command like following image:

If your tab is not inserting space instead focusing then following solution will work for you

2 Comments

Mine said "Tab Moves Focus". Clicking it solved the issue.
This has been driving me crazy. Only started happening within the last year. I have removed all keybindings to Tab except for tab. Tab Moves Focus gets turned on seemingly at random. Annoying. I turn it off. Maybe it starts to work maybe it doesn't. But even if it works it is fairly brief before it doesn't work again. Tab Moves Focus button is no longer there to turn it off. No way to get it back without restarting VSCode. Then it works but oh so briefly as sooner or later Tab Moves Focus comes back on OR it just starts acting ilke it even if the notficiation not lit.
3

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

1 Comment

Same for me!!! I never open a TeamViewer, and I accidentally left it open. To add more info: I had another instance of VS Code running, and in it the tab was working fine, while in the other tab was not working. After closing TeamViewer, tab works in both instances!
2

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

Comments

2

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

Comments

1

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 ↹.

It works for me. Some extension overwrite it.

Comments

0

Make sure this is NOT checked:

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

1 Comment

Is this related with Visual Studio? The question is asked for VS Code I guess.
0

Had the same issue on Mac. The Ctrl+Shift+M solution was not the correct one in my case. The indentation of a code line when pressing the Tab key was not possible because the key binding for indentation was set to a 4-key combination.

I did reset it to Tab ↹ in the key bindings settings (Preferences > Keyboard Shortcuts) and added && !config.emmet.triggerExpansionOnTab to the when expression, since I use the emmet plugin.

Comments

0

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

1 Comment

Ctrl+M still works for me on vscode 1.64.1 on Windows. What version of vscode are you on?
-2

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:

1 Comment

The latest update didn't do it for me - I pulled the March insiders release and that worked great.
-2

Problem could be caused by an Application on your computer

For me the problem got solved after closing Any Desk on my computer . I had it open to change some files on my remote server, and it's blocking the ability to tab
If you want to check , open your task manager and you will find it there. just right click it and select end task and tab will be back to normal.

AnyDesk

Comments

-2

My issue was that the file wasn't editable by VS Code. You'll see a small padlock on the file tab on top. Just close the tab and open the file again. Tab ↹ should be working as usual.

Comments