Using Vim with ALE for Python linting and autocompletion

At work we use VS Code but if possible I would prefer not to use that on my work station at home. Since I’ve been apt purging nano for ages I started looking for a way to do this with Vim. In the end it turned out to be quite simple on my Debian Bookworm install.


You will need the following packages:

  • vim
  • flake8
  • python3-pylsp
  • vim-ale

Install them with sudo apt install vim flake8 python3-pylsp vim-ale.


Add the following lines to your .vimrc and you should be good to go!

packadd! ale
let g:ale_completion_enabled = 1
let g:ale_linters = {'python': ['pylsp']}

On Ubuntu the situation is a bit different, the linter to add for autocompletion is called pyls but the executable is called pylsp. So to have ALE load the correct executable some extra configuration is needed.

packadd! ale
let g:ale_completion_enabled = 1
let g:ale_linters = {'python': ['pyls']}
let g:ale_python_pyls_executable = 'pylsp'

Todo: Check if flake8 dependency is really needed.

Using Vim with ALE for Python linting and autocompletion

Living in a shell

Since I started working for my new employer the amount of time I’m spending inside a terminal window is rapidly increasing. And I like it. I’m learning more in a few months than I did in the past 5 years. I’m discovering superhandy commands and utilities that I had never used or even heard of before. Utilities like w, last and the various *stat utilities. And I’m becoming better and better in using utilities that I already know but that always remained hard to grasp simply because I didn’t use them extensively. Think of Vim, screen and sed. Or on a lower level, the Bash shell itself.

I’m particularly starting to develop a fondness for Vim. I’ve worked myself through a complete Vim book and when I finished it I was like, Vim is not arcane at all, it’s actually quite simple. It’s all about terseness, doing things in the fastest, most efficient way, memorizing the most important commands and forcing myself to use it for things I would normally do in say, gedit. So now I find myself easily copying whole blocks of text, commenting and uncommenting multiple lines with just a few keystrokes, using markers and buffers and browsing faster through files than possible with a mouse.

Currently I’m reading a book on Bash and it already provided me with a lot of new insights and ideas that I could use in my daily work. My scripting skills are a bit feeble so hopefully this book will help me to improve these. Luckily I have great colleagues that are very knowledgeable when it come to things like Bash and Vim so I’m coming along just fine. But I want to be able to purge a Sendmail mail queue filled with spam like I saw one of my colleagues do recently. What he did on top of his head was just amazing:

for i in `ls | grep qfr`; do w=`grep $i | wc -l`; if [ "$w" != "0" ]; 
then echo $i | sed -e 's/^qfr//'; fi;  done | sed -e 's/^/*/' | xargs -n 50000;

This allowed him to create a list of all spam messages which he simply ran through rm. It’s no rocket science but I’d really like to be that proficient too. Another colleague of mine is just awesome with regular expressions and Vi. For example, I recently asked him how I could delete all text between parentheses including the parentheses, for example a list of packages I copied from /var/log/apt/history.log, and he immediately replied %s/([^)]*)//g. Yes, I’m blessed that I can work in such an inspiring environment.

Living in a shell