Align key-value pair in PyCharm
Is it possible to set a pair of Align key values in the Pycharm code style? I'm looking for something that will reformat:
nickname = models.CharField(unique=True, max_length=24)
biography = models.TextField(default=BIO_DEFAULT_STRING)
avatar = models.ImageField(upload_to='members/avatars/')
in
nickname = models.CharField(unique=True, max_length=24)
biography = models.TextField(default=BIO_DEFAULT_STRING)
avatar = models.ImageField(upload_to='members/avatars/')
I got it in PhpStorm, can't find it in PyCharm.
source to share
You need a function from the String Manipulation plugin :
Menu
→ Code
→Align to Columns
Configure hotkeys
-
Settings
→Keymap
- Find "Align Columns" and select
-
Add Keyboard Shortcut
( Enter) - Install shortcuts (mine Ctrl+ K)
- Click
Apply
andOk
source to share
It's really weird, but PyCharm 2016 has this stuff and I had to look for a way to turn it off. I found this question while searching for "How to align by value".
File - Preferences - Editor - Code Style - Python
There you need the Other tab where you will find the Dict Aligment settings . There are 3 types:
- Do not align
- Align by value
- Colon align
Not sure why they added this stuff, maybe due to platform unification, but it exists and changed to by default 'Align on value'
for me after I updated PyCharm to 2016.2.
UPDATE:
Litle a bit more explanation:
A question has been asked about how to create alignments in PyCharm code generation, for example in dicts .:
This is how the dict should look like via PEP:
i_am_a_dict = {
key:value,
another_key:another_value,
a_very_long_key:one_more_value
}
How it looks in PyCharm after platform update (and this format is NOT PEP compliant, but it can be done using PyCharm settings:
i_am_a_dict = {
key: value,
another_key: another_value,
a_very_long_key:one_more_value
}
It has been value aligned. And the question was about how to "align key: values in PyCharm"
source to share