Keyboard Shortcut - Multi Line Comment

It would be great if I could select multiple lines of python code and hit a keyboard shortcut key to comment/uncomment the selection.

Try using Ctrl + /

3 Likes

Oh wow. This works but it wasn’t documented on the Keyboard Shortcuts page

https://anvil.works/docs/editor/keyboard-shortcuts

What other undocumented shortcuts do we get :slight_smile:

I’m not sure but I think, as far as I know, this one is fairly common. At least, I see it in many other IDEs.

3 Likes

For undocumented shortcuts here’s a list

https://defkey.com/codemirror-shortcuts

Anvil ide uses code mirror. There are some really useful ones

cmd-c copies the line you are on
cmd-g iterates through the last thing you searched
cmd-d deletes the line you are on
cmd-u undo last selection
cmd-] indent the current line

etc…

6 Likes

Is there a way to do this on Mac? Couldn’t find anything in the docs or codemirror.

The Mac equivalent of Ctrl + / with control or command buttons also didn’t work for me.

I recently discovered that ALT-mouse-drag produces a multi-line cursor. With this cursor, I was able to insert and delete # characters on multiple lines at once. Does that work with your browser?

1 Like

Wow…that’s blown my mind. It does work for me, on Chrome. I’m not quite sure what I’d use it for.

I recall a programmer who carefully lined up his source code, spreadsheet style, in rows and columns, just so that he could edit a bunch of formulas at once that way… Those lines were hundreds of characters long. :exploding_head:

In practical terms, however, this might be used for [un]commenting multiple lines of code, e.g., to track down a problem, or for [de-]indenting a code block.

It also makes sense when editing the text of a columnar report. Sometimes you need a column to be wider (or narrower).

I use the Alt+drag selection all the times. It is a little better than simple columnar editing. If your fingers don’t get entangled with Ctrl+Shift+Arrows and other shortcuts, you can do slightly fancier things like this:

MultiSelection

1 Like

I am surprised that list doesn’t include Ctrl+Q to fold/unfold a region. Unfortunately only works on one region, not on the selected text or the whole file, but I accidentally found out about it and I was expecting to see it in that list.