简体   繁体   中英

How to run isort via ALE in Vim?

I want to set up isort to be used in Vim via the ALE plugin. I've added this shortcut to my .vimrc :

nnoremap <leader>I :ALEFix isort<CR>

However, when I activate it nothing happens. I have isort installed both globally and in the virtualenv. Could anyone give me a hint how to debug/solve this issue?

From ALE's README.md

ALE can fix files with the ALEFix command. Functions need to be configured either in each buffer with ab:ale_fixers, or globally with g:ale_fixers. The recommended way to configure fixers is to define a List in an ftplugin file.

The proper way of configuring isort is by setting g:ale_fixers in your vimrc / init.vim or b:ale_fixers in ftplugin/python.vim .

Eg

" setting it globally
let g:ale_fixers = {
            \ 'python': ['black', 'isort'],
            \ }

Any command line options you want to pass to isort you do it by setting g:ale_python_isort_options .

let g:ale_python_isort_options = '--profile black -l 100'

If you want to automatically fix files when you save them, you need to turn a setting on in vimrc.

" Set this variable to 1 to fix files when you save them.
let g:ale_fix_on_save = 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM