Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using the ALE plugin to format Python code with Black. Black indents the file with spaces (it's the same case with AutoPep8), but I want to keep my tabs. So I wrote this keybinding to run Black then swap spaces with tabs:

nnoremap <leader>ff :ALEFix<cr>:%retab!<cr>

When I run this, it works, but when I run it again the spaces stay there, and when I run it again it works, and so on. I works for one time, does not for the next, and so on...

I tried this as well, but got the same result:

nnoremap <leader>ff :ALEFix<cr>gg=G

What should I do so that it always runs correctly, runs Black, then always returns back my tabs?

question from:https://stackoverflow.com/questions/65641088/vim-format-python-code-with-black-and-then-force-tabs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
261 views
Welcome To Ask or Share your Answers For Others

1 Answer

What I can surmise is that you are using the auto fix on save feature of Ale. When you save the file it turns your tabs to space as black doesn't support tabs and neither does Autopep8.

Autopep8 does seem to have some way to get tabs. See this link.

You can check the GitHub for issue regarding spaces vs tabs in case of black and autopep8


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...