Sublime Forum

Double click redefinition

#1

I’m just started to evaluate Sublime Text and found it quite interesting, but to start use it I need to make some of custom definitions for my needs. I have searched the web but not found how can I redefine a double click selection. My interest is to select everything within matching brackets including the brackets if I’m clicking outside. The action I need is the same like a double shortcut ctrl+shift+m.

1 Like

#2

In your package user directory (ctrl+shift+p -> Browse Package), create a file Default.sublime-mousemap and copy paste:

[
	// Drag select by words
	{
		"button": "button1", "count": 2,
		"press_command": "expand_selection",
		"press_args": {"to": "brackets"}
	}
]

To know the command you can just have a look at the keybinding in menu Preference -> Settings Default.

1 Like

#3

Thank you, Clams, it works near to I need but selects everything inside brackects only and gets no brackets itself. I would like to get a double ctrl+shift+m action result by double mouse clicking.

1 Like

#4

It is not possible to queue directly multiple command with a key/mouse-bind but there is plugin for that, described in this topic. I never tested it, but hopefully it helps.

1 Like

#5

Thank you for the hint but neither “run_multiple_commands.py” nor http://stackoverflow.com/questions/9646552/is-it-possible-to-chain-key-binding-commands-in-sublime-text-2/10863489#10863489 works. Probably the reason is both samples made for ST2 but I evaluate ST3.

OK, I will search further to get double shortcut functionality for double click because it is the main option for me.

1 Like

#6

I made something quick that should work:

Create a file xxx.py in your package user directory with:

import sublime, sublime_plugin

class DoubleBracketExpandCommand(sublime_plugin.TextCommand):

    def run(self,edit):
        self.view.run_command('expand_selection',{"to": "brackets"})
        self.view.run_command('expand_selection',{"to": "brackets"})

Now you can change the press_cmd to “double_bracket_expand” and remove the press_args.

If I have some time I might do an ST3 version of the run_multiple_command plugin, because it looks like it could be useful.

1 Like

#7

I changed but still not works.

{
“button”: “button1”, “count”: 2,
“command”: “DoubleBracketExpandCommand”
}

Is it correct?

1 Like

#8

No, it should be

[
	{
		"button": "button1", "count": 2,
		"press_command": "double_bracket_expand"
	}
]

When you create a plugin with a format like MyPluginCommand, to call it you need to use “my_plugin”

1 Like

#9

Thank you very much for your help and explanations!
You just made my decision to order for ST3 :slight_smile:

1 Like