dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.51k stars 1.43k forks source link

InsertLeave Event Emulation #4605

Closed w0rp closed 1 year ago

w0rp commented 1 year ago

One of the most annoying details about how InsertLeave behaves in Vim by default is that you can leave insert mode by mashing CTRL+C, and by default this differs from hitting the Escape key in that the former does not trigger an InsertLeave event, while the latter does. Many users resort to writing inoremap <C-c> <Esc> as a result, which allows InsertLeave to be triggered when you leave insert mode. ALE's default is to run linters when you leave insert mode, which happens to be one of the best opportunities to check code, and this default is not applied to anyone with a fresh Vim or Neovim install.

To make the default experience better for users, we can emulate leaving insert mode. When g:ale_lint_on_insert_leave is set to 1, we will add an InsertEnter autocmd event which starts an interval timer. The timer will continue to run until the buffer eventually returns to Normal mode, at which point ALE will start linting. This behaviour will only be enabled if we can detect that <C-c> is not bound to <Esc> and the timer will be killed on an InsertLeave event.