Python Forum

Full Version: How to instantly add quotation marks and comma for parameters?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

Does someone know how to instantly add quotation marks and comma for parameters?
For example:

data  = {
   type: a
   type: b
   type: c
}
I need to make the parameters as dictionary as below:
{
   'type': 'a',
   'type': 'b',
   'type': 'c'
}
In a Python tutorial, I saw an instructor instantly adds quotation marks and commas for the dictionary. He does not add them one by one, or write regular expresses in PyCharm. I guess he must use a certain extension for it.

Does someone know about this?

Please advise me.

I use VS Code.
I would argue that this is not 'instantly'. There is no mind-reading plugins :-). Other than that - yes, there are several ways to achieve desired result with keyboard shortcuts.

In VS Code and for surrounding with " it quite straightforward: select text and press ".

If you need to surround " in column (as in this code snippet) then use multi cursor: place the cursor at the start of the first line, press ⌥ ⌘ ↓ (MacOS) to add another cursor below on the next line. Keep doing that until you have a cursor in front of all your words. Then just type " then fn → (END) then " and all your lines are surrounded by quotes (you can end with ", when needed). If you skip end part then you can just add at the beginning which is simple way to comment out parts of code (ESC for exiting multi cursor mode).

To find out what is your multi cursor keyboard shortcut use ⌘ SHIFT P (CTRL-SHIFT-P in Windows) and type "Add Cursor Below".

For more advanced use cases there are plugins or you can map code snippets to Keyboard Shortcut JSON.
Hello perfringo,

Thank you very much for your help. Sorry, I forgot to state I use desktop, operation system is Windows. I have some relevant questions as below:

1. Would you please tell me what's 'fn →' in Windows?
(I've searched it on the Interent, but found nothing. The rest MacOS keys that you show here are okay, and I've found them out in Windows.)
2. The following screenshot in gif is how that Python instructor makes the parameters as dictionary very soon. Could you please possibly figure out how he does this and tell me?
[Image: BiPEwD.gif]
On Win keyboards there is key conveniently named 'End' Wink (which is missing from MacOS keyboard). I indicated that in my original post, albeit not very obviously.

This will move you to end of line. For more precision use SHIFT → to select character wise.

Regarding example you provided - you can observe that this is some sort of multi cursor (they are visually seen) but I have no experience with PyCharm to help. It might by something built-in, some plugin or Keyboard shortcut to execute some formatting-code snippet.
Thank you very much for your help. Smile