devil0150
devil0150

Reputation: 1469

Is there a way to toggle selection in Sublime Text?

I don't like keeping the shift button pressed while moving the cursor. I'm looking for something similar to emacs, where you press Ctrl+Space, move the cursor to where you want (while the text is highlighted), and press Ctrl+Space again to finish the selection.

I looked at the keymap file but the only thing I could find is setting the mark. Doing that doesn't keep the text highlighted while I move the cursor, and it also uses two different keybindings to start and end the selection.

Can this be done in sublime text? Whether it's 2 or 3 doesn't matter.

Upvotes: 1

Views: 415

Answers (1)

r-stein
r-stein

Reputation: 4847

You could use a context and toggle a setting on ctrl+space , this would result in this keybinding:

{ "keys": ["left"], "command": "move", "args": {"by": "characters", "forward": false, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["right"], "command": "move", "args": {"by": "characters", "forward": true, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["up"], "command": "move", "args": {"by": "lines", "forward": false, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["down"], "command": "move", "args": {"by": "lines", "forward": true, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["ctrl+left"], "command": "move", "args": {"by": "words", "forward": false, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["ctrl+right"], "command": "move", "args": {"by": "word_ends", "forward": true, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["alt+left"], "command": "move", "args": {"by": "subwords", "forward": false, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["alt+right"], "command": "move", "args": {"by": "subword_ends", "forward": true, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["pageup"], "command": "move", "args": {"by": "pages", "forward": false, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["pagedown"], "command": "move", "args": {"by": "pages", "forward": true, "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["home"], "command": "move_to", "args": {"to": "bol", "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol", "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["ctrl+home"], "command": "move_to", "args": {"to": "bof", "extend": true}, "context": [{"key": "setting.do_extend"}] },
{ "keys": ["ctrl+end"], "command": "move_to", "args": {"to": "eof", "extend": true}, "context": [{"key": "setting.do_extend"}] },

{ "keys": ["ctrl+space"], "command": "toggle_setting", "args": {"setting": "do_extend"} },

Upvotes: 2

Related Questions