Four Emacs Commands To Remove Lines

Emacs Elements has been vlogging up a storm lately and has another useful video on Emacs line commands. The video covers four Emacs commands that all deal with removing lines from a buffer. The four commands that the video considers are:

  1. flush-lines
  2. kill-matching-lines
  3. keep-lines
  4. copy-matching-lines

The first two commands, flush-lines and kill-matchinfg-lines, both remove lines that match a regular expression. The difference is that flush-lines deletes the lines without adding them to the kill ring, whereas kill-matching-lines does the same thing but also adds the deleted lines to the kill ring.

The situation is similar with keep-lines and copy-matching-lines. The keep-lines command deletes all lines that don’t match the regular expression, while the copy-matching-lines command simply copies the lines that match to the kill ring but doesn’t delete anything.

There are several subtleties involved with the use of these commands. For example, in the absence of a region, they work like search in that they work from the point to the end of the buffer but anything before the point is unaffected. There are also rules about what the region must cover and casefolding so be sure to watch the video for the details.

It’s a nice video that explains some really useful commands. It’s only 5 minutes, 34 seconds long so it should be easy to fit in.

This entry was posted in General and tagged . Bookmark the permalink.