Shortcut to fold/unfold all the code in the IDE editor

In PyCharm I use Ctrl Shift + and Ctrl Shift - to unfold or fold everything and Ctrl Alt + and Ctrl Alt - to unfold or fold the region containing the caret.

The most important is Ctrl Shift - which allows to hide all the code with the exception of the top level statements and declarations, giving an outline of the classes.

I would really really really love to have these shortcuts in the Anvil editor.

(@stucork, any idea about a workaround? :grinning:)

3 Likes

Well, you could always just switch to neovim :wink:

(and there are some suggestions on StackOverflow)

1 Like

neovim… I will give it a try, it will be like traveling back in time for me.

I worked for a few years in vi, in the late eighties, before vim or linux even existed.
If you ask me what key corresponds to what command, I’m not going to be able to answer, I forgot everything.
Today, when I put my hands on a vim editor I don’t know what to do, but my fingers automagically know what to do. And I’m there, amazed, looking at my hands able to yank and paste chunks of code and get the job done.
Then, when I’m done, you ask me again, and I still don’t remember how to do what I have just done.

1 Like

I had to sit at my keyboard just now to work out how to do the folding. My fingers know but my mind does not!

I have a dotfiles repo with my neovim config, in case that’s of any use.

I work on Windows, nvim is not there and I have unsuccessfully tried to install it. Do you have any advice for me?

Here is what I did:

  • Install the Firenvim extension to Chrome from Firenvim - Chrome Web Store

  • Download nvim-win64.zip from Release NVIM v0.5.0 · neovim/neovim · GitHub

  • Copy the Neovim folder to C:\Program Files

  • Execute C:\Program Files\Neovim\bin\nvim.exe and tell Windows you trust it (I don’t know if I need this, but I did it anyway)

  • Create a virtual environment with pynvim (I use Anaconda, which doesn’t have pynvim):

    • conda create --name neovim python
    • activate neovim
    • pip install pynvim
  • Execute C:\Program Files\Neovim\bin\nvim-qt.exe and:

    • :let g:python_host_prog='C:\Users\stefanomenci\AppData\Local\conda\conda\envs\neovim\python.exe'
      
  • Start PowerShell and execute (see here):

    iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |`
      ni "$(@($env:XDG_DATA_HOME, $env:LOCALAPPDATA)[$null -eq $env:XDG_DATA_HOME])/nvim-data/site/autoload/plug.vim" -Force
    

I don’t understand what the following steps listed here do in Linux and how to do them in Windows.

The Firenvim browser plugin for neovim reminds of an Excel VBA macro that I made that starts when I press Ctrl+Shift+Alt+E. The macro saves the content of the active cell to a text file, starts a text editor with that file and starts polling the modification time of the text file.

When the text file is saved the macro reads the content and replaces the cell text.

This little VBA macro allows me to edit and format large formulas, json objects or various scripts that I often stash inside Excel cells and are very difficult to manage with the limited cell editing native in Excel.

It looks like this plugin does something similar: saves the content of a TextArea to a text file and runs the nvim text editor installed on the computer. It does it nicely, embedded in the browser’s TextArea rather than in the editor UI, but the concept is similar.

Doing this in Excel + VBA is easy because I have full access to the cell’s content, the file system and the executables, while in a browser is more difficult because of the browser’s security constraints.

At this point, rather than wasting more hours trying to configure a bunch of tools so they talk to each other in Windows and finally being able to work with an editor I’m not familiar with, I would rather create my own jerry rigged plugin that selects the TextArea text, copies and pastes it in PyCharm and viceversa.

Or just use the good old pull / edit / push workflow with PyCharm.

Or wait for the fold/unfold shortcuts to be available in the Anvil editor.

Or wait for a PyCharm plugin that allows to edit the code, while keeping the web interface for the form editor. So I would have multiple editors open on the same app at the same time, yay!!

Wow, that sounds like a lot of work. I haven’t used Windows for more than a decade, so I don’t have much to offer, I’m afraid (and you’ve reminded me why that’s the case)!

1 Like

Unfortunately I have to use Windows, because I use CAD, CAM and other applications only available on Windows.
And I have to use Excel VBA.
Yay!!

Now that we have a new editor… what about adding a shortcut to fold all the foldable regions?

6 Likes

Update - the firenvim browser extension now supports neovim running within WSL2 on windows, so that might be an option here.

3 Likes

If I’m doing some heavier stuff, I just clone locally and use PyCharm. Great for refactoring things too.

THE SHORTCUTS ARE HERE!!!

(unfortunately Ctrl-Shift-[ only works if you are on the first line of the block, but I can live with that)

1 Like
Currently you can do Ctrl-Shift-[ (Cmd-Alt-[ on macOS): foldCode. Ctrl-Shift-] (Cmd-Alt-] on macOS): unfoldCode. Ctrl-Alt-[: foldAll. Ctrl-Alt-]: unfoldAll.

whats the Alt key on a mac keyboard ? ( google said the Option key) that doesn’t work in either classic of beta editor for me

on Mac alt is the option key.
You’ll need to be on the first line of the code block for code fold to work. And fold all should just work. (Works for me on Mac)

( keyword: code block!!) indeed it is !! thanks @stucork

I removed the [Done] from the subject because the Ctrl-Alt-[ is useless as is. It doesn’t really fold all, it only folds the top level, not the lower levels.

This makes it impossible to fold all, then unfold one class and see the members of the class. If you unfold the class, all its members are unfolded and you are at the starting point, wasting your time scrolling up and down.

2 Likes