Here’s another quick one. It could be when formatting pieces of code that you want to remove any space from the beginning of the line. Removing de-facto any indentation.
M-x query-replace-regexp RET
Confirm then one by one with ‘y‘ or replace all of the buffer with ‘!‘.
Spiral-Bound Pad (by incurable_hippie)
Here is a quick way to strip (remove) blank lines from a file with emacs.
- position on top of file: M-<
- Call a query-regex-replace: M-C-%
- input the regex ^ C-q C-j that stand for match all lines that consist in only a carriage return.
- RET-RET. The first one confirm the regex and the last one is for “replace with nothing”.
- When asked use ! to replace-all.
Summing all commands:
M-< C-M-% ^ C-q C-j RET RET !
here you are 🙂
It happened that I needed to count all lines of code in all java/jsp files of a project. What faster than bash can do this?
$ find -type f -iregex ‘.+\.j\(sp\|ava\)$’ -print0 | xargs -0 wc -l
However this wont skip the blank lines.