I am figuring out a way to apply linting to a visual selection of code. For example:

enter image description here

I only want to lint run :ALEFix on that section of code, and not the 100s (or 1000s) of lines of other code in the file. My first thought was doing something like:

  • Copy the visual selection. y
  • Option a new file and paste that in. :vs tmp
  • Run :AleFix on that shortened file.
  • Copy-all: ggVG"*y
  • Close that file :q!
  • Do gv to re-highlight the visual selection at the start.
  • Paste in the copy-buffer p

What might be a better way to do that? And if the above seems like it might be the best way, what might be a clean function to do that with? (I'll try writing one myself as well...)

1 Answer 1


A little rough around the edges, but here is what I came up with (which I've tested and works for me):

function _AleVisualSelection()
    normal! gvy
    vs tmp
    ALEFix black
    normal! ggVG
    sleep 300m

vnoremap    0   <Esc>:call _AleVisualSelection()<CR>y:q!<CR>gvp

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.