Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change tab size on GitHub?

When I view files on GitHub, tabs appear as 8 spaces.

Example:

example

Is that possible to change this configuration to 2 or 4 spaces?

like image 513
Misha Moroshko Avatar asked Jan 12 '12 11:01

Misha Moroshko


People also ask

How do I change the indent size in GitHub?

If you use tabs to indent your code in your editor and push the code to Github, you might notice that your tab appears as 8 spaces. According to stackoverflow contributors here, you can change the tab size by clicking edit on the file itself and change the indentation configuration.

How many spaces is a tab in GitHub?

Tab Size on GitHub. Update: GitHub now has a tab size setting: https://github.blog/changelog/2021-09-21-tab-size-rendering-preference/ By default, in browsers, the tab character takes up 8 spaces in width. This makes tab-indented code hard to read.

Does GitHub use tabs or spaces?

You can manage the number of spaces a tab is equal to for your personal account. If you feel that tabbed indentation in code rendered on GitHub takes up too much, or too little space, you can change this in your settings.


2 Answers

You can append ?ts=2 or ?ts=4 to the URL to change the tab-size.

Example: https://github.com/jquery/jquery/blob/main/src/core.js?ts=2

It seems that the value can be anything from 1 to 12. It does not work on Gists or raw file views though.

Source: GitHub Cheat Sheet

like image 75
mortenpi Avatar answered Oct 21 '22 07:10

mortenpi


Set default displayed tab size for your repository

When you have a .editorconfig in your repository it will respect it when viewing code on GitHub.

indent_style = tab and indent_size = 4 shows tabs with 4 columns instead of 8 https://github.com/isaacs/github/issues/170#issuecomment-150489692

Example .editorconfig for multiple extensions which works in JetBrains' products:

root = true  [*] end_of_line = lf insert_final_newline = true  # Matches multiple files with brace expansion notation [*.{js,jsx,html,sass}] charset = utf-8 indent_style = tab indent_size = 4 trim_trailing_whitespace = true  [*.md] trim_trailing_whitespace = false 

Change how you see tabs on other repositories

Install Stylus in your browser, than install GitHub: better-sized tabs in code.

There are also Google Chrome extensions:

  • https://chrome.google.com/webstore/detail/github-tab-sizer/djpnapkcpjomnkfekaedkigfomiedpjf
  • https://chrome.google.com/webstore/detail/github-tab-size/ofjbgncegkdemndciafljngjbdpfmbkn/related
like image 24
rofrol Avatar answered Oct 21 '22 08:10

rofrol