Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode insert tab character manually

When using VSCode, most of my files are set to be indented using spaces. However I sometimes wish to insert a literal tab. When I was using vim I'd use <Ctrl>+v <Tab> but that doesn't work with VSCode.

I've been searching and searching and cannot find anything. Please help!

like image 316
Christopher Causer Avatar asked Aug 08 '17 11:08

Christopher Causer


People also ask

How do I change the Tab key in VS 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).


2 Answers

Quick-and-dirty solution: Find a tab somewhere else, then copy-paste.

Chances are that you already have a tab character in the file you are editing, but if not you can generate one in another application or text editor.

You can also generate a tab programmatically in a bash shell with the following command (the brackets are optional):

echo -e [\\t] 

For your more immediate needs, I have inserted a tab character below...

     There is a tab character between these brackets: [	] 

Another approach is to change the tab mode temporarily, as shown here.

like image 67
Brent Bradburn Avatar answered Oct 02 '22 20:10

Brent Bradburn


I'm not sure if there is a generic solution, but you can setup a keybinding for this:

{     "key": "ctrl+v tab",     "command": "type",     "args": { "text": "\t" },     "when": "editorTextFocus" } 

This keybinding will insert an tab character even when the current mode is spaces.

like image 43
Matt Bierner Avatar answered Oct 02 '22 18:10

Matt Bierner