chelder
chelder

Reputation: 3987

Sublime Text: keyboard shortcut to select a function and its content

function whatever(){
    var = a;
    return a;
}

Is there any shortcut to select all of the above code?

I know Ctrl+Shift+M will select the content within the parenthesis.

Upvotes: 2

Views: 1208

Answers (1)

MattDMo
MattDMo

Reputation: 102852

If you're using JavaScript, you might want to check out the Expand Selection to Function (JavaScript) plugin, available via Package Control. Once installed, there should be an Expand Selection to Function (JavaScript) option in the Selection menu, as well as in the Command Palette. The initial keybinding for the function is Alt, but that didn't work for me running Ubuntu under VMWare Fusion (OS X host), so I added an option to Preferences -> Key Bindings-User:

{ "keys": ["ctrl+shift+g"], "command": "expand_selection_to_function_javascript" }

If the file is empty when you open it, surround the above command with square brackets []. I chose CtrlShiftG because is wasn't bound to anything else. If you're running Ubuntu as your only OS (i.e., not as a virtual machine), then Alt may work just fine.

The plugin itself actually works quite well. Given the following function:

function foo(bar, baz) {
    return bar + baz;
}

or:

foo: function (bar, baz) {
    return bar + baz;
}

or even an anonymous function:

function() {
    alert("FUBAR!");
}

you can click on the function keyword, the function name, or anywhere inside the function, hit the key binding, and everything will be selected.

Upvotes: 2

Related Questions