Sublime Text如何快速删除空格?


正常的代码排版是这样:


 <div>
    <div>
        <p></p>
        <p></p>
    </div>
</div>

缩进正常,可是经常从一个文件复制代码到另外一个文件的时候,缩进就乱了。
变成类似这样:


 <div>
        <div>
            <p></p>
            <p></p>
        </div>
</div>

这个要怎么快速排版?当代码很长的时候,一行行删除空格很累。

工作效率 前端 sublime-text 代码排版 sublime-text3

低调的过客 9 years, 7 months ago

额,平时都选中乱的那些行,然后 tab 往后缩,或者 shift+tab 往前缩,上面两位的方法挺好的

メīǎò辉‰ answered 9 years, 7 months ago

对于程序块缩进可用快捷键:
←左缩进 ctrl + [
→右缩进 ctrl + ] ,效果等同 tab 键;
比如代码:


 1 <div>
2         <div>
3             <p></p>
4             <p></p>
5         </div>
6 </div>

选中:2-5行,快捷键 ctrl + [ ,就会向左缩进:


 <div>
    <div>
        <p></p>
        <p></p>
    </div>
</div>

更多Sublime Text 3快捷键请参考: Sublime Text 3 快捷键大全

louise. answered 9 years, 7 months ago

可以配置保存后自动去掉行末空格


 "trim_trailing_white_space_on_save": true

你这个是缩进的问题,我的配置你可以看看

http://blog.libnav.com/essay/448.html

你也可以试试:编辑-》行列-》重新缩进

马萨卡!? answered 9 years, 7 months ago

Ctrl+A 所有代码或部分代码, Edit -> Line -> Reindent

HTML文件/代码, 记得保证右下角的显示的是" HTML "而非其他语言, 不然重新缩进的时候不会根据HTML来缩进.

快捷键暂时不知道. 可以自己定义如下:
1. 点击 Preferences -> Key Bindings - User
2. 加入: { "keys": ["f12"], "command": "reindent"} , 如果默认什么都没有的话, 得写:
[{ "keys": ["f12"], "command": "reindent"}] 格式语法就是 json 语法

这样你就能按 F12 来格式化了, 要先 CTRL+A , 再 F12

用google搜索 sublime text 2 reindent shortcut , 排名第一的 stackoverflow 就是了.


来, 再教你个大招, 不用ctrl+a, 又不用自定义快捷键的:
ctrl+shift+p , 输入 reindent , 然后它会显示个 Indentation: Reindent Lines , 用上下键选择它, 回车. 前提是装了"package control"

kkoom answered 9 years, 7 months ago

Your Answer