Sublime Forum

Folding Via Hotkey, rather than Clicking

#1

Is it possible to fold a block just from placing your cursor over it and hitting a hotkey? (is there a command yet for that?)

Currently I can only do that by clicking on the icon:

1 Like

#2

Go to Edit > Code Folding. It will list all the coding options and keyboard shortcuts.

1 Like

#3

I just tried those, but it won’t work unless I select code.

What I want is to actually just fold whatever block the cursor is on.

0 Likes

#4

From the command on the toolbar it still won’t work…
Help please? :smile:

0 Likes

#5

I guess I’ll make a plugin for you…

0 Likes

#6

The key bindings listed in the Edit / Code Folding menu will fold the block the caret is on if no text is selected, or if there’s a selection, they’ll fold the selected text.

0 Likes

#7

I can get the second option to work ( select text + folding command )

But the first one is not working, at least not as expected.

I think this is a bug.

I have the following code:

.pagination { @include pagination; }

I’m expecting that placing the cursor anywhere near those 3 lines and doing fold, will actually fold that given block. However it won’t work if I place the cursor anywhere on the first or third line, it’ll only work on the second line.

:frowning:

0 Likes

#8

I’m also trying to make the fold / unfold hotkeys work with one single key with a plugin sublimator wrote for me, but it seems it won’t work the same way:

import sublime_plugin

[code]class ToggleFold(sublime_plugin.TextCommand):
‘{“keys”: “f1”], “command”: “toggle_fold”}’
def run(self, edit):
view = self.view

    if any(not view.fold(sel) for sel in view.sel()):
        map(view.unfold, view.sel())[/code]
0 Likes