How do I use the trim function correctly on Shimano shifters
H: To be used with the smaller cogs of the cassette.

HT: To be used with the larger cogs of the cassette. You might hear a rubbing noise  of the chain on the inner blade of the front derailleur if there's a large cog in use at the rear and the front is still on H.

L: You'll use it when the chain is on one of the larger rear cogs.

LT: For when the chain begins rubbing on the FD when you shift on one of the smaller rear cogs.

On a safe flat road put the chain on the smallest cog, the biggest ring and start shifting the rear derailleur towards larger cogs. Look down on the FD and not the behaviour of the chain between the two blades of the FD. At one point, you'll notice the chain touching the FD. That's the point where you trim the FD.

Note: when you shift at the front, the derailleur will go to L or H. Depending on the situation at the rear, you'll have to trim at the front right after the chain has fallen on the small front ring or climbed on the big ring.