I have the following function:

function _X()
    normal! gvy
    vs tmp
    ALEFix black
    normal! ggVG
    normal! y <-------

Unfortunately, the y does not work. That is, when it runs within the function whatever it copies is not correct (as if the function didn't finish the job yet). However, as soon as the function exits I can press y and it will copy the selection, but not within the function. What's going on here, and how can I fix that behavior?


ALE's readme says

ALE offers support for fixing code with command line tools in a non-blocking manner with the :ALEFix feature

so ALEFix is asynchronous and your yanking commands would need to wait for it to complete before they run.

If you look further in the Readme in the FAQ there is How can I execute some code when ALE starts or stops linting? The plugin provides autocommands to handle this kind of situations:

augroup YourGroup
    autocmd User ALELintPre    call YourFunction()
    autocmd User ALELintPost   call YourFunction()

    autocmd User ALEJobStarted call YourFunction()

    autocmd User ALEFixPre     call YourFunction()
    autocmd User ALEFixPost    call YourFunction()
augroup END

Here you'll probably need to use ALEFixPost to run your yanking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.