Eclipse 多行缩进使用制表符而不是空格 (pydev)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9008958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse multi-line indent uses tabs instead of spaces (pydev)
提问by zzz
When I highlight a block of text in Eclipse, and press TAB, it inserts a tab at the head of each line. I want it to insert 4 spaces instead.
当我在 Eclipse 中突出显示一个文本块并按 TAB 时,它会在每行的开头插入一个制表符。我希望它插入 4 个空格。
I need to do this on a files with a custom extension: *.shpaml
我需要对带有自定义扩展名的文件执行此操作:*.shpaml
I have PyDev installed.
我已经安装了 PyDev。
回答by Fabio Zadrozny
I'm considering that *.shpaml is opened with the PyDev editor...
我正在考虑使用 PyDev 编辑器打开 *.shpaml ......
There are 2 preferences related to that:
有 2 个偏好与此相关:
In window > preferences > PyDev > Editor, you can choose 'replace tabs with spaces when typing?' and in that same page 'assume tab spacing when file contains tabs?'.
在窗口 > 首选项 > PyDev > 编辑器中,您可以选择“键入时用空格替换制表符?” 并在同一页面中“当文件包含制表符时假设制表符间距?”。
So, probably you have both checked and your *.shpaml has some tab in it, which makes PyDev work with tabs... if you uncheck the 'assume tab spacing when file contains tabs?', it should do what you want.
所以,可能你已经检查过并且你的 *.shpaml 中有一些选项卡,这使得 PyDev 可以使用选项卡......如果你取消选中“文件包含选项卡时假设选项卡间距?”,它应该做你想做的。
回答by paulsm4
You should be able to set "spaces instead of tabs" here:
您应该能够在此处设置“空格而不是制表符”:
Eclipse, Window, Preferences, General, Editors, Text Editors,
Insert spaces for tabs=Y
回答by intotecho
Use the settings: Eclipse, Window, Preferences, General, Editors, Text Editors, Tick 'Replace tabs with spaces when typing' This was 'Insert spaces for tabs' in older Eclipse versions)
使用设置:Eclipse、窗口、首选项、常规、编辑器、文本编辑器,勾选“键入时用空格替换选项卡”这是旧 Eclipse 版本中的“为选项卡插入空格”)
The new name makes it clearer that this option only applies to typing and not indenting with the tab key.
新名称更清楚地表明此选项仅适用于键入而不适用于使用 Tab 键缩进。
Also untick setting 'Assume tab spacing when files contain tabs'
Otherwise Eclipse will still fall vack to tab spacing when files contain tabs'.
Opening files in other editors may still lead to tabs.
在其他编辑器中打开文件可能仍会导致出现选项卡。
It is also wise to remove all the existing tabs from your file. Open each file, then from the Find-Replace Function (Ctrl-F), tick 'Regular expressions' then Find: \t and Replace by 4 spaces.
从文件中删除所有现有选项卡也是明智之举。打开每个文件,然后从查找替换函数 (Ctrl-F) 中,勾选“正则表达式”,然后查找:\t 并替换为 4 个空格。
Or Source -> 'Convert tabs to space-tabs'
However, tabs will still be inserted by the Shift Left and Multi-line tab key. Two options are to convert the tabs back to spaces using one of the above methods or instead of using tab or shift-right, right-click on the selected block and choose one of the 'Quick fix' options such as surround the block with an if, while or try - if that is appropriate in the context.
但是,制表符仍会通过左移和多行制表键插入。两个选项是使用上述方法之一将制表符转换回空格,或者不使用制表符或右移,右键单击所选块并选择“快速修复”选项之一,例如用如果,同时或尝试 - 如果这在上下文中是合适的。
回答by kslote1
Additionally, I had this same problem when making sure a module was PEP8 compliant and had to do this for code that was already written in which case the method above does not work.
此外,我在确保模块符合 PEP8 时遇到了同样的问题,并且必须对已经编写的代码执行此操作,在这种情况下,上述方法不起作用。
Go to windows > preferences ? PyDev ? text editor click show whitespace characters. Highlight a tab and click cntrl f. Paste the tab whitespace into find box and four spaces into the replace with box. Hit replace all.
转到窗口 > 首选项?PyDev ? 文本编辑器单击显示空白字符。突出显示一个选项卡并单击 cntrl f。将选项卡空白粘贴到查找框中,将四个空格粘贴到替换框中。点击全部替换。