Actually, less does not have a built-in "save" feature like a bookmark manager for search patterns that persists after you close the program.
However, there are three ways you can effectively manage and reuse search patterns:
1. The Command History (The Easiest Way)
less remembers your search history during your current session and even across different sessions (stored in a file called ~/.lesshst).
- Open a file with
less. - Press
/to start a search. - Use the Up/Down arrow keys on your keyboard. This will cycle through the patterns you have searched for previously.
2. Using the Shell History
If there is a complex pattern you use frequently, you can include it in the command when you open the file:
less +/ERROR\|WARNING server_log.txt
Next time you need it, you can simply use the shell's history (press the Up arrow in your terminal) to bring back that specific command.
3. Using Environment Variables
If you have a very complex regular expression that you use every day, you can save it as an alias or an environment variable in your .zshrc or .bashrc file.
For example, you could add this to your configuration:
alias checklogs='less +/"ERROR\|CRITICAL\|FATAL"'
Then, you would only need to type checklogs server_log.txt to start your custom search immediately.
Summary: While less doesn't have a "Save Pattern" button, using the Up arrow after pressing / is the standard way to find your previous searches! Why not try searching for "ERROR", then "INFO", and then use the Up arrow to switch between them?