Question

Motivation: I was going around assigning parameters read in from a config file to variables in a function like so:

john = my_quest
terry = my_fav_color
eric = airspeed
ni = swallow_type
...

when I realized this was going to be a lot of parameters to pass. I thus decided I'd put these parameters in a nice dictionary, grail, e.g. grail['my_quest'] so that the only thing I needed to pass to the function was grail.

Question: Is there a simple way in Sublime (or Notepad++, Spyder, Pycharm, etc.) to paste grails['variable'] around those variables in one step, instead of needing to paste the front and back seperately? (I know about multiple cursors in Sublime, that does help, but I'd love to find a "highlight-variable-and-hit-ctrl-meta-shift-\" and it's done.)

Was it helpful?

Solution

Based on examples you provided, this is a simple task solvable using standard regex find/replace.

So in Notepad++, record this macro (for recording control examine Macro menu):

  1. Press Ctrl+H to open Find/Replace dialog
  2. Find what: = (.*)$
  3. Replace with: = grail['\1']
  4. Choose Regular Expression and press Replace All

If you finish recording the macro and you choose to save it, shortcut key is requested. Assign your favorite ctrl-meta-shift-\ and you are done.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top