emacs strip blank lines

Spiral-Bound Pad

Spiral-Bound Pad (by incurable_hippie)

Here is a quick way to strip (remove) blank lines from a file with emacs.

  1. position on top of file: M-<
  2. Call a query-regex-replace: M-C-%
  3. input the regex ^ C-q C-j that stand for match all lines that consist in only a carriage return.
  4. RET-RET. The first one confirm the regex and the last one is for “replace with nothing”.
  5. When asked use ! to replace-all.

Summing all commands:

M-< C-M-% ^ C-q C-j RET RET !

here you are 🙂

[emacs] sorting lines

I will never stop saying how much I love emacs. I have to admit that it’s very difficult to learn how to use it and even after you have learned enough to use it, you will always find something that you didn’t know.

The task for today is simple: sorting the lines in a region. There’s an already existent macro: sort-lines. So first you will have to select the region and the call the macro. In the following example we will sort the lines of the whole document.

C-x h <RET> M-x sort-lines

Again: easy easy and easy 🙂