例如,当我缩进某个类的成员以使它们对齐时,它在Visual Studio中看起来很好看,但在GitHub中看起来很丑陋。
这是一个例子:
![Indentation in Visual Studio](https://istack.dev59.com/FLgr1.webp)
首先,请确保您的缩进是实际制表符,而不是空格。
其次,默认情况下,GitHub 会将制表符显示为 8 个字符。
因此,请尝试查看相同的 GitHub 页面,但在其 URL 结尾处添加:?ts=4
即:
https://gist.github.com/razzorflame/ef776ddef260608bc1a8799090af629e?ts=4
或者... 配置您的Visual Studio,使用8个制表符宽度(虽然不是理想的选择)。如此处所提到的,您可以添加一个.editorconfig
(像这个一样用于gist):
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
.editorconfig
的示例,Git本身在Git 2.26(2020年第一季度)中告诉.editorconfig
,在此项目中,*.txt
文件使用制表符缩进。illikainen
)于2020年1月5日完成)。gitster
--合并于提交34246a1,2020年1月30日)
editorconfig
: indent text files with tabsSigned-off-by: Hans Jerry Illikainen
Previously, the
.editorconfig
did not specify an indentation style for text files.However, a quick look for indentation-like spacing suggest that tabs are more common for documentation:
$ git grep -Pe '^ {4}' -- '*.txt' |wc -l 2683 $ git grep -Pe '^\t' -- '*.txt' |wc -l 14011
Note that there are a lot of files that indent list continuations (and other things) with a single space -- if the first search was made without the fixed quantifier the result would look very different.
However, the result does correspond with my anecdotal experience when editing Git documentation.This commit adds
*.txt
to.editorconfig
as an extension that should be indented with tabs.
.editorconfig
文件。请看我的编辑后的答案。 - VonC