Linux 工具/编辑器可以在编写代码后很好地自动格式化我的代码
我正在寻找一个工具或编辑器,可以在其中粘贴可能混乱的代码,无论是 HTML、Javascript、CSS 等等,并正确处理所有缩进和间距。
我使用 Geany,但令人惊讶的是我没有看到此选项。我不知道在 vim 或 emacs 中是否可以。任何帮助将不胜感激。
HTML 示例:
<!DOCTYPE html>
<html>
<body>
<ul>
<li>what a mess</li>
</ul>
</body>
</html>
I'm looking for a tool or editor where I can paste in potentially messy code, be it HTML, Javascript, CSS, whatever, and properly take care of all indentation and spacing.
I use Geany but I don't see an option for this, surprisingly. I don't know if it's possible in vim or emacs. Any help would be appreciated.
Example HTML:
<!DOCTYPE html>
<html>
<body>
<ul>
<li>what a mess</li>
</ul>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
vim 和 emacs 都会让你按照你的要求去做。我相信在 vim 中你想使用 'gg=G',而 emacs 是 Cx CM-\
我希望这会有所帮助。
Both vim and emacs will let you do what you ask. I believe in vim you want to use 'gg=G', and emacs is C-x C-M-\
I hope this helps.
有一些命令行工具可以提供帮助(例如,C 的“缩进”),但“Edd 的 Emacs 和 vi 的建议可能是适用于所有语言的最佳工具”。
There are some command line tools that can help (eg, 'indent' for C), but 'Edd's suggestion of Emacs and vi are probably the best that will work on all languages.
您可以重新格式化/漂亮打印起始 HTML,然后在您选择的编辑器中处理结果文件。例如,在 Linux 上,您可以使用 Tidy 在编辑 HTML 之前清理它;你会使用这样的命令,
(感谢这个答案中的@shmit提供指向Tidy的指针)
You could reformat/pretty-print the starting HTML and then work with the resulting file in the editor of your choice. For example on Linux you could use Tidy to clean up the HTML before editing it; you'd use a command like this,
(thank you to @shmit in this answer for the pointer to Tidy)