To fight a monster, you just try to move onto the same space that the monster occupies.
F is the explicit fight command. Its use is to attack peaceful monsters without confirmation, attack a pet without displacing it, or strike at the suspected location of an invisible monster without moving if it is not there.
Fighting at a space containing no monster produces the message "You attack thin air."
m is an explicit move command. If you want to attempt to move onto a space without attacking its occupant then press m before selecting your direction.
The two commands are generally associated with hallucination, invisibility and blindness, since these warrant more caution than the usual move-attack function. At most other times directional control is sufficient.
If you attempt to attack a peaceful creature (by trying to move onto the same square as it, not by using F) it will display a message saying "Really attack the (name of creature)? [yn] (n)". It has "no" selected by default, but you can press y to attack the peaceful creature.