Emacs: List/Delete Matching Lines, Sort Lines
- List all lines in the current file that matches a given text.
Clicking the line will jump to the match location in the file.
If you want to match with word boundary, use
\b, like this
\bcat\b. This will find “cat” but not “cats”. [see Emacs: Regex Tutorial]
- Count matching lines.
Delete Matching Lines
- Delete lines that match a regex. Works on text selection or starts at the line your cursor is on. (alias of
- (alias of
- Delete duplicated lines in text selection.
- Sort lines in text selection.
- Reverse lines order in text selection.
- Sort lines by a specific column, as number. For example: Type Ctrl+u, then 2, then Alt+x
sort-numeric-fields. This will sort the line by the 2nd column, and the fields are compared as numbers.
- Sort lines by a specific column, as string. (“fields” are separated by space or tabs. First field is 1.)
Escape Regex Chars
All these commands use regex to search. So, if you simply want to search plain words or phrases, and if your phrase contains any of regex characters, you need to escape them.
Common regex chars that need backslash before:
[ ] \ + * ? .
See also: common patterns in emacs regex.
Letter Case Sensitivity
In all these commands, if your search word contains upper case letters, then the search is automatically case sensitive. Otherwise, it is not case sensitive.
If you want case sensitive, Alt+x
toggle-case-fold-search. Remember to toggle it back.
List Lines in ALL Buffer
multi-occur if you want to list lines in ALL buffers.