How can I un/comment out code in MySQL Workbench using a keyboard shortcut?

半腔热情 提交于 2019-11-30 04:55:36

Thanks for filing the bug report, it's annoying.

If you have a full size keyboard try using the division symbol.
i.e. The CONTROL + "/" using the division key above the keypad instead of the "?/" key on the main keyboard.

It's not nearly as convenient, but it works for me with Windows 7 and MYSQL Workbench 6.1.

Works for me when I press either of the Ctrl buttons + / ("slash button" in Num Pad)

Instead you can also simple type "#" at the Point of line you want to comment.

  • example: #SELECT * FROM images where category_name = "cars"; comments the whole line

I can confirm that this works on OS X and Linux, but it's failing on Windows. This is likely a bug, please file a bug report at bugs.mysql.com.

It is now May 2019 and this is still an open issue. There is a work around there but it doesn't work either. Here is what I have done for my v8.0.15.

Close MySQL Workbench if you have it open. Find the menu XML file at [path-to-mysql-workbench-folder]\data\main_menu.xml. Open in any editor and search for toggle comment. You should find this menu item:

<value type="object" struct-name="app.MenuItem" id="com.mysql.wb.menu.edit.
  <link type="object" key="owner" struct-name="app.MenuItem">
    com.mysql.wb.menu.edit.format_menu</link>
  <value type="string" key="accessibilityName">Toggle Comment on Selection</value>
  <value type="string" key="caption">Un/Comment Selection</value>
  <value type="string" key="name">comment</value>
  <value type="string" key="command">plugin:wb.sqlide.comment</value>
  <value type="string" key="itemType">action</value>
  <value type="string" key="shortcut">Modifier+Slash</value>
</value>

Change the key="shortcut" portion from Modifier+Slash to anything that isn't taken, and that does not contain 'Slash' in it. I have it set to Modifier+Alt+D. Feel free to set it to what helps you, and try out different combinations if you are having issues. Start up MySQL Workbench and try out your fully working shortcut!

Don't forget you can also manually do this by going to the menu Edit -> Format -> Un/Comment Selection. You can also use the division symbol (forward slash) near the full size keypad if you have one. This should work without any changes, but not nearly as convenient.

On my keyboard, in Windows 10, I found to make this work I needed to:

  1. select the text to be commented
  2. press Fn key
  3. press CTRL+/
  4. when done, press Fn key
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!