I've just installed python-mode
, and it has lots of cool features like "syntax-checking".
I like to have 2-spaces of indentation for my python code but the syntax-checking is warning me that it should be 4 spaces.
I believe there should be a variable for me to set this preference. I've read through the docs of pymode, I can't find the related setting.
(Plus, I want to change the shiftwidth setting set by pymode also)
The size of the tab character is controlled with the Editor > Indentation > Default Tab Size preference.
In most other programming languages, indentation is used only to help make the code look pretty. But in Python, it is required for indicating what block of code a statement belongs to.
The best way to do it is to make a file in .vim/ftplugin/python.vim
, and put this in:
setlocal smarttab
setlocal expandtab
setlocal shiftwidth=2
setlocal tabstop=2
setlocal softtabstop=2
This would apply across all of your Python files. Another way is the modeline: put this at the top or at the bottom of all of your Python files to affect only those files:
# vim: sta:et:sw=2:ts=2:sts=2
This requires that you have modeline support switched on, which probably requires you to have set modeline
in your .vimrc
.
But as rednaw says, it's not exactly a good idea, and if you do do it it's probably best to only do it to the files you make and not all Python files (i.e. leave the ones that are written by other people to be formatted as standard), so I recommend the second method if you really need to do it.
You can have multiple lints. Add this to your ~/.vimrc
keeping only the checkers you want.
let g:pymode_lint_checkers = ['mccabe', 'pyflakes', 'pylint', 'pep8', 'pep257']
Trying here with a 2-line indented code, the only messages that appears and are related to the indentation are:
These could be easily removed changing the same file:
let g:pymode_lint_ignore = 'E111,W0311'
As well as other messages, if you need. You can also choose to use fewer checkers instead of creating a message code blacklist.
IMHO, style shouldn't be standardized rigidly with annoying checkers. I don't use pylint, pep8 nor pep257, and a configuration like this doesn't need a pymode_lint_ignore
, as it was only for pylint and pep8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With