The shell is often able to complete words when given a unique abbreviation. Completion in the middle of a word often results in leftover characters to the right of the cursor which need to be deleted. Commands and variables can be completed in much the same way.
Completion can find a command in any directory in path or if given a full pathname.
The shell parses the input buffer to determine whether the word you want to complete should be completed as a filename, command or variable. Anything else is a filename. The shell variable fignore can be set to a list of suffixes to be ignored by completion. Periods, however, are not equivalent to hyphens or underscores. Finally, the complete builtin command can be used to tell the shell how to complete words other than filenames, commands and variables.