DEV Community

Cover image for Vs Code one tip a week: code folding
Aurelio
Aurelio

Posted on • Updated on • Originally published at nobitagit.github.io

Vs Code one tip a week: code folding

Code folding can make browsing long files easier. When we're trying to focus on the big picture without being distracted by smaller details code folding can be an invaluable aid.


This is an effort to learn how to get the best out of Vs Code keyboard shortcuts without feeling overwhelmed.

Learning how to use our favourite IDE without a mouse can make a big difference.
Since an extension like the amazing Key Promoter for Jetbrains seems to be far from being a reality for now at least, I started collecting my favourite keyboard tricks in bite sized chunks.

The idea is simple: find one tip you like, practice it the whole week until you've really mastered it and made it part of your workflow and then move to the next one.


To fold a block

⌘ + OPTION + [
Enter fullscreen mode Exit fullscreen mode

To unfold it:

⌘ + OPTION + ]
Enter fullscreen mode Exit fullscreen mode

Users of Vs Code with Vim extensions

The above command will work for all users of VsCode. Those using a vim emulation extension like VsCodeVim or amVim will have an extra pair of shortcuts to choose from.

To fold a block, switch to normal mode and:

z + c
Enter fullscreen mode Exit fullscreen mode

Where "c" stands for "close".

To unfold:

z + o
Enter fullscreen mode Exit fullscreen mode

Where "o" stands for "open".

Further shortcuts

Note that you can also fold and unfold an entire file, but I find that less useful and never really felt the need to memorise that shortcut combination.

Resources

Originally published on my blog.

Top comments (4)

Collapse
 
danielhobson profile image
Daniel Hobson

For Windows users:

Fold:

  Ctrl + Shift + [

Unfold:

  Ctrl + Shift + ]
Collapse
 
aurelio profile image
Aurelio

Nice! Thanks for adding it!

Collapse
 
zovorap profile image
Anton Burov

Thanks Daniel.
I was surprized that the article doesn't contain an option for Windows, but contains one for vim extension, which makes it useless for the majority of users.

Collapse
 
gerbosan profile image
Carlos A.

Under openSuSE Leap 15.1 Linux, VS Code 1.36.1, keyboard Spanish Latinamerica

to open

Ctrl + {

to close

Ctrl + }