21

In iTerm2 you can create triggers that highlight a line if your regex matches. This is great for some cases but I was wondering if it was possible to highlight only a word on a specific line.

The purpose of this is to help read my server logs where specific keywords can be easily pointed out. Highlighting the entire line is a bit distracting

2 Answers 2

41

A Profile-based trigger can highlight as much or little of a line as you choice (via the regex).

To highlight just a "word" in a line, you can create a simple Highlight Text trigger, i.e.:

enter image description here

Results in:

enter image description here

Ref: https://iterm2.com/documentation-triggers.html

Below is where you will find Triggers enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Ahh I see. The regex I was using must be selecting the entire line. Thank you!
Very helpful to highlight certain packages in stacktrace!
10

As an additional usage of the selected answer, I'd like to suggest adding a tigger for "smart quotes" with the regex [”“’‘]

Example of iTerm2 > Preferences > Profiles > Advanced > Triggers > Edit

This will save you some day when a coworker sends you a line of code via a chat mechanism (like Slack) and the quotes get automagically "improved". The trigger won't fire as you paste/type them, but they will happen after the line scrolls up your terminal. So, it won't prevent the mistake, but it will save you time wondering why the command failed.

Example of triggered smartquotes

2 Comments

If you tick the "instant" checkbox to the right then it will highlight as soon as you paste the code in, which is quite handy :)
Not a bad idea. Heck, add nbsp's and other non-printables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.