f0rsman
f0rsman

Reputation: 396

Issue with gist indentation

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.

Upvotes: 27

Views: 1450

Answers (4)

Soonts
Soonts

Reputation: 21926

While creating the gist, that setting is indeed broken. Github says this is by design, LOL.

Luckily, there’s another setting in the account preferences, which does work. That setting is “Tab size preference” on the following page: https://github.com/settings/appearance

The default value is 8. The setting applies globally, and it also affects the gists you view while logged in.

Upvotes: 1

Saad
Saad

Reputation: 3430

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

Upvotes: 0

kiyah
kiyah

Reputation: 1528

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.

Upvotes: 1

Priyesh Patel
Priyesh Patel

Reputation: 74

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.

Upvotes: 0

Related Questions