Issue with gist indentation

Viewed 1077

When creating a Gist on Github there is a setting for indentation (tabs or spaces; size 2, 4, or 8). After setting indents to tabs size 4, it changes to tabs size 8 after I save it. Editing it afterwords doesn't do anything. Other settings don't produce the expected result either. Am I misunderstanding this feature somehow? Can't find any documentation regarding this.

3 Answers

I replaced tabs with four spaces in Notepad++ (Ctrl+H), and it works. You can use any numbers of spaces.

Those tabs are automatically displayed as a 8-character-tab in Github Gist.

This is happening because while writing the code, you used the tab key which inserted 8 spaces. Here's a solution that I use.

  1. Copy all your code to a local file and open it in the vi editor. cat>temp.js ctrl+shift+v to paste and ctrl+d to save.

    vim temp.js (Or change the extension as per your file.)

  2. Run the following command that I found from here. This will half the existing space.

    :%s;^\(\s\+\);\=repeat(' ', len(submatch(0))/2);g

  3. Press the esc key then :x and enter key to save and exit vi.

  4. Copy the code in your temp.js file and paste it in your gist with spaces as 4.

Convert the indentation from Tabs to Spaces or Spaces to Tabs by using vscode with the easy and simple following steps.

  1. Open the file with vscode.
  2. Press,
    • On MacOS, command + shift + p
    • On Windows, ctrl + shift + p
  3. Type "convert indentation to spaces" and select then option. (As shown in the below fig)
  4. Save the file. (ctrl+s / ⌘+s)

enter image description here

Related