BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Posterne
Fluorite | Level 6

Hi all,

 

I'm trying to create a keyboard shortcut that will automatically make marked text into a comment.

 

What I want is for it to do the following:

/* [marked text] */ ;

 

My problem is, I don't know how to reference marked text when creating the shortcut.

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Posterne,

 

This is a good idea! Thanks for sharing.

 

It seems that you don't necessarily want to comment out a whole line (which is what the Ctrl+/ shortcut does -- but not so easily on non-English keyboards btw.), but only selected text such as a word or a couple of words or several lines of code.

 

You can set up a keyboard macro containing a sequence of Enhanced Editor commands for this task:

 

  1. From the main menu (with an Enhanced Editor window being active) select Tools --> Keyboard Macros --> Macros...
  2. Click "Create..." button.
  3. Enter a name and (optionally) a description for your keyboard macro.
  4. Select Miscellaneous (or All -- but this list can be very long) from the drop-down list "Categories".
  5. Select "Cut selection" from the "Commands" list and click the double-arrow button to put the command into the "Keyboard macro contents" box.
  6. Select "Edit" from the "Categories" list and "Insert a string" from "Commands".
  7. Click the double-arrow button, type /*  */ into the pop-up Window "Insert String" and press "OK".
  8. Select "Navigation" from the "Categories" list and "Move cursor left" from "Commands".
  9. Click the double-arrow button three times.
  10. Select "Navigation" from the "Categories" list, "Paste from clipboard" from "Commands" and click the double-arrow button.
    Now the "Create Keyboard Macro" window should look something like this:
    create_kbd_macro.png

     

  11. Click "OK".
  12. Click "Assign keys..." button in window "Keyboard Macros" (which should now be open automatically, with the new macro selcomm selected).
  13. Click into the field "Press new shortcut key", then press your desired keyboard shortcut, e.g. Ctrl+F3. (If there are no conflicts*, the message "Currently assigned to: None" will be displayed.)
  14. Click "OK".
  15. Click "Close" to close the "Keyboard Macros" window.
  16. Test the keyboard macro.

As you can see from the commands, the macro uses the clipboard. Hence, you shouldn't use it while you have something important in the clipboard. But I think this is only a minor limitation.

 

*EDIT: "no conflicts" refers only to other Enhanced Editor keyboard shortcuts. There could still be a conflict with a definition from the KEYS window and with shortcuts from the operating system or other software. So, select the shortcut with that in mind.

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What software are you using.  The old Locally installed SAS editor used to let you press:

Control + /

To comment a line, and

Control + Shift + / 

To uncomment (or a keystroke like that, been a while since I used it).  Unfortunately the editors are really quite old and clunky now, the "Enhanced Editor" came out with version 8, and hasn't had any updates.  Not sure what Enterprise uses or the other packages.  It would be great to have a decent editor/IDE, but I don't see it happening any time soon.

 

What I tend to do is drop a new row before and after and put the /* and */ on these extra lines, that way you only need to add/remove those rows to comment/uncomment.

 

As for kjeyboard shortcuts, you would need to be a bit more specific.

Posterne
Fluorite | Level 6

I'm using SAS base 9,4 and as far as I can see, there is no "create comment" shortcut (at least not listed in "Keys"). So I'm in trhe enhanced editor, in "Keys", and i want to make the open shortcut ctl + F3 a shortcut to making marked text into a comment.

FreelanceReinh
Jade | Level 19

Hi @Posterne,

 

This is a good idea! Thanks for sharing.

 

It seems that you don't necessarily want to comment out a whole line (which is what the Ctrl+/ shortcut does -- but not so easily on non-English keyboards btw.), but only selected text such as a word or a couple of words or several lines of code.

 

You can set up a keyboard macro containing a sequence of Enhanced Editor commands for this task:

 

  1. From the main menu (with an Enhanced Editor window being active) select Tools --> Keyboard Macros --> Macros...
  2. Click "Create..." button.
  3. Enter a name and (optionally) a description for your keyboard macro.
  4. Select Miscellaneous (or All -- but this list can be very long) from the drop-down list "Categories".
  5. Select "Cut selection" from the "Commands" list and click the double-arrow button to put the command into the "Keyboard macro contents" box.
  6. Select "Edit" from the "Categories" list and "Insert a string" from "Commands".
  7. Click the double-arrow button, type /*  */ into the pop-up Window "Insert String" and press "OK".
  8. Select "Navigation" from the "Categories" list and "Move cursor left" from "Commands".
  9. Click the double-arrow button three times.
  10. Select "Navigation" from the "Categories" list, "Paste from clipboard" from "Commands" and click the double-arrow button.
    Now the "Create Keyboard Macro" window should look something like this:
    create_kbd_macro.png

     

  11. Click "OK".
  12. Click "Assign keys..." button in window "Keyboard Macros" (which should now be open automatically, with the new macro selcomm selected).
  13. Click into the field "Press new shortcut key", then press your desired keyboard shortcut, e.g. Ctrl+F3. (If there are no conflicts*, the message "Currently assigned to: None" will be displayed.)
  14. Click "OK".
  15. Click "Close" to close the "Keyboard Macros" window.
  16. Test the keyboard macro.

As you can see from the commands, the macro uses the clipboard. Hence, you shouldn't use it while you have something important in the clipboard. But I think this is only a minor limitation.

 

*EDIT: "no conflicts" refers only to other Enhanced Editor keyboard shortcuts. There could still be a conflict with a definition from the KEYS window and with shortcuts from the operating system or other software. So, select the shortcut with that in mind.

Posterne
Fluorite | Level 6

Just what i needed!

FreelanceReinh
Jade | Level 19

I will use it, too. Thanks again.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1557 views
  • 1 like
  • 3 in conversation