3

So lets say I have the argument pyautogui.typewrite(["tab"]) and I want to remove the [] brackets to switch from a key to a string, when I click in-front of the last bracket is shows the first bracket highlighted as-well. How do I delete the first bracket at the same time as the last bracket? There must be a way since both brackets are highlighted before I delete last bracket.

1 Answers1

3

Steps to follow,

  • In the Macro Menu, click Start Recording and perform the below steps
  • Select the text you want to remove the square brackets from
  • Use the shortcut Ctrl + H to open the Replace window
  • Use this regex \[|\] in the Find what field and replace it with an empty string
  • Make sure you check the In selection box and select Regular Expression in Search Mode section
  • Click Replace All
  • Close the Replace window and under the Macro Menu, click Stop Recording
  • Test the recorded macro using the Playback option in the Macro Menu
  • If satisfied, save the recorded macro by selecting Save Current Recorded Macro under Macro menu and then assign a shortcut to it

Note: \[|\] this regex matches either [ or ]

Alternatively, you can just edit your shortcuts.xml file by adding this to the Macros section,

<Macro name="test" Ctrl="yes" Alt="yes" Shift="yes" Key="68">
   <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
   <Action type="3" message="1601" wParam="0" lParam="0" sParam="\[|\]" />
   <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
   <Action type="3" message="1602" wParam="0" lParam="0" sParam="" />
   <Action type="3" message="1702" wParam="0" lParam="896" sParam="" />
   <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
</Macro>

Here, the name of the macro is test and the shortcut assigned is Ctrl+Shift+D (ASCII value of D is 68)

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
  • Thank you for the response, I was hoping there would be an easier way like holding ctrl + del or something. To be clear, I only want to delete the the opening [ on the specific line I'm working on when I delete the closing ]. Would the macro apply to all lines or only the line I'm working on? – Kevin Burris Jun 19 '19 at 18:32
  • 1
    @KevinBurris, It would apply only to the current selection of text, however you could change that when you are recording the macro – Saurabh P Bhandari Jun 20 '19 at 00:13
  • 1
    @KevinBurris, I have added the easier way too, check the second part of the answer – Saurabh P Bhandari Jun 20 '19 at 00:14
  • 2
    @KevinBurris, the closest shortcut notepad++ provides for braces are "Go to Matching Brace" and "Select all between matching braces", you can find other shortcuts under Shortcut Manager located under settings – Saurabh P Bhandari Jun 20 '19 at 00:18
  • Thank you, I appreciate it. – Kevin Burris Jun 20 '19 at 16:26