bugfix: maximum index should be length-1
Trim really long patterns otherwise Vim will throw an error