I am trying to disable vscode from formatting my python imports when I save my file. I have some code that must run in between various imports so order is important, but every time I save it just shoves the imports to the top.
I tried putting
"editor.codeActionsOnSave": {"source.organizeImports": false
},
in my user settings but that doesn't fix it.
Thanks!
EDIT- I would like to keep formatting on save on except for the imports
Check for the below setting in vscode settings, if it's true then set it to false for completely disabling formatting on save, like so :
"editor.formatOnSave": false
for formatting and to ignore imports not being at top itself, first make the above setting true and add to your user settings and try adding this setting to your user settings, if you're using the default formatter for python, that is autopep8 :
"python.formatting.autopep8Args": ["--ignore","E402"]
where E402 represents "module level import not at top of file"
Note that this would only work if you are using the default formatter/linter. If you are using some other linter then i suggest you look up their documentation to see how it's done. Like most commonly one could make use of global config file, say $HOME/.config/.pycodestyle, and add necessary settings there, like :
[pycodestyle]
ignore = E402
EDIT : the arguments for the formatter should be passed as separate list items in quotes like ["--ignore","E402"] rather than [--ignore=E402]