In this article we develop a vectorial kernel method-a powerful method which solves in a unified framework all the problems related to the enumeration of words generated by a pushdown automaton. We apply it for the enumeration of lattice paths that avoid a fixed word (a pattern), or for counting the occurrences of a given pattern. We unify results from numerous articles concerning patterns like peaks, valleys, humps, etc., in Dyck and Motzkin paths. This refines the study by Banderier and Flajolet from 2002 on enumeration and asymptotics of lattice paths: we extend here their results to pattern-avoiding walks/bridges/meanders/excursions. We show that the autocorrelation polynomial of this forbidden pattern, as introduced by Guibas and Odlyzko in 1981 in the context of rational languages, still plays a crucial role for our algebraic languages. En passant, our results give the enumeration of some classes of self-avoiding walks, and prove several conjectures from the On-Line Encyclopedia of Integer Sequences. Finally, we also give the trivariate generating function (length, final altitude, number of occurrences of the pattern p), and we prove that the number of occurrences is normally distributed and linear with respect to the length of the walk: this is what Flajolet and Sedgewick call an instance of Borges's theorem. Keywords Lattice paths • Dyck paths • Motzkin paths • Łukasiewicz paths • Pattern avoidance • Autocorrelation • Finite automata • Markov chains • Pushdown automata • Generating functions • Wiener-Hopf factorization • Kernel method • Asymptotic analysis • Gaussian limit law • Borges' theorem We dedicate this article to the memory of Philippe Flajolet, our cheerful and inspiring mentor, founder of analytic combinatorics.