Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For those that are curious how the autocorrect does its magic, here is the code https://github.com/git/git/blob/master/help.c#L293.

The most important part of the algorithm is the line "levenshtein(cmd, candidate, 0, 2, 1, 3) + 1;". This calculates the levenshtein distance between what you typed and valid commands, using different weights for different types of manipulations. In this case, 0 for swaps, 2 for substitutions, 1 for adds and 3 for deletes.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: