
十里(5km)笔记
Tab键Soft和Hard之分
用 Atom 时发现 Tab 类型有 Soft 和 Hard 之分,原来 Soft 是按 Tab 插入固定数量的空格,Hard 插入真正的制表符。这篇用一句话讲清楚两者区别:Soft 是绝对的,Hard 是相对的。
0次点击2分钟阅读
这怪之前孤陋寡闻,在使用编辑器Atom时,进入设置看到Tab type(Tab类型),咦,tab还有Soft和Hard之分呀,Settings中关于 Tab Type 的提示如下:
Determine character inserted when Tab key is pressed. Possible values: "auto", "soft" and "hard". When set to "soft" or "hard", soft tabs (spaces) or hard tabs (tab characters) are used. When set to "auto", the editor auto-detects the tab type based on the contents of the buffer (it uses the first leading whitespace on a non-comment line), or uses the value of the Soft Tabs config setting if auto-detection fails.
根据上面内容可知,原来是在编辑文本文档时,当设置类型为 Soft 则按下Tab键插入空格符(个数便是tab size设置的大小),当设置为 Hard 则按下Tab键便插入一个Tab符,当设置为 Auto 的时候,编辑器便会根据所编辑文件内的风格进行设置,判断首次缩进位置所使用的风格。
其实,这也不难想到,Soft类型插入的缩进无论到哪儿大小肯定不变,会一直是你想要的样子,而Hard类型会根据在不同环境中设置的tab大小进行缩进,往往导致不统一,这对于强迫症的我简直不能忍,我还是希望编辑的代码到每个地方缩进是统一的,那么Soft才是我需要的,这印证一个说法:
Soft方式是绝对的,Hard是相对的。
无论什么类型,自己喜欢就好!



