简体   繁体   中英

How to delete empty lines in a file using Emacs?

In Emacs, how to remove all empty lines (including tabs and spaces) in file?

Can Mx replace-regexp do the trick?

I can find the empty lines with regexp: ^[st]*$ , but don't know how to replace it by deleting.

Mx flush-lines RET ^[[:space:]]*$ RET可能是规范的方法。

^ and $ just match starts and ends of lines, not the actual end-of-line characters. You have the explicitly type the newline in the expression to replace it.

To achieve your goal, replace-regexp

^[[:space:]]*^J

with nothing (empty text). To enter ^J , first press Control and Q, then Control and J. In the entry field, this shows up as an actual line change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM