欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

如何用Sublime Text 2中的选项卡替换四个空格?

程序员文章站 2024-01-08 09:00:40
...

本文翻译自:How to replace four spaces with a tab in Sublime Text 2?

如何用Sublime Text 2中的选项卡替换四个空格?

I want to replace all the "four spaces" that is written by another text editor with tabs. 我想用标签替换另一个文本编辑器写的所有“四个空格”。 How can I do it? 我该怎么做?


#1楼

参考:https://stackoom.com/question/eB5P/如何用Sublime-Text-中的选项卡替换四个空格


#2楼

To configure Sublime to always use tabs try the adding the following to preferences->settings-user: 要将Sublime配置为始终使用选项卡,请尝试将以下内容添加到preferences-> settings-user:

{
    "tab_size": 4,
    "translate_tabs_to_spaces": false
}

More information here: http://www.sublimetext.com/docs/2/indentation.html 更多信息请访问: http//www.sublimetext.com/docs/2/indentation.html


#3楼

create a keybinding for quickest way 以最快的方式创建一个键绑定

{ "keys": ["super+alt+t"], "command": "unexpand_tabs", "args": { "set_translate_tabs": true } }

add this to Preferences > Key Bindings (user) when you press super + alt + t it will convert spaces to tabs 当你按下super + alt + t时 ,将它添加到Preferences> Key Bindings(用户) ,它会将空格转换为制表符


#4楼

You could add easy key binding: 您可以添加简单的键绑定:

Preference > Key binding - user : 首选项>键绑定 - 用户:

[
    { "keys": ["super+l"], "command": "reindent"},
]

Now select the line or file and hit: command + l 现在选择行或文件,然后点击:command + l


#5楼

If you want to recursively apply this change to all files in a directoy, you can use the Find > Find in Files... modal: 如果要以递归方式将此更改应用于directoy中的所有文件,可以使用“查找”>“在文件中查找...”模式:

如何用Sublime Text 2中的选项卡替换四个空格?

Edit I didn't highlight it in the image, but you have to click the .* button on the left to have Sublime interpret the Find field as a regex /Edit 编辑我没有在图像中突出显示它,但你必须单击左侧的。*按钮让Sublime将查找字段解释为正则表达式/编辑

Edit 2 I neglected to add a start of string anchor to the regex. 编辑2我忽略了向正则表达式添加字符串锚点的开头。 I'm correcting that below, and will update the image when I get a chance /Edit 我正在纠正下面的内容,并在我有机会/编辑时更新图像

The regex in the Find field ^[^\\S\\t\\n\\r]{4} will match white space characters in groups of 4 (excluding tabs and newline characters). 查找字段^[^\\S\\t\\n\\r]{4}的正则表达式将匹配4个组中的空格字符(不包括制表符和换行符)。 The replace field \\t indicates you would like to replace them with tabs. 替换字段\\t表示您要用标签替换它们。

If you click the button to the right of the Where field, you'll see options that will help you target your search, replace. 如果单击“位置”字段右侧的按钮,您将看到可帮助您定位搜索,替换的选项。 Add Folder option will let you select the folder you'd like to recursively search from. Add Folder选项将允许您选择要从中递归搜索的文件夹。 The Add Include Filter option will let you restrict the search to files of a certain extension. Add Include Filter选项将允许您将搜索限制为特定扩展名的文件。


#6楼

在主菜单上;

View -> Indentation -> Convert Indentation to Tabs / Spaces

相关标签: editor sublimetext