Sublime Forum

Vintage - Keep selection going from Visual to Insert mode

#1

Hello, first of all, I love ST2 and Vintage!

I am having a bit of an issue though, is it at all possible to go from Visual Mode to Insert Mode and still keep the selection alive? I find that pressing I or A eliminates the selection I had. Thank you for the help.

0 Likes

#2

I have not found any way to make it so. It’s a shame; vintage mode makes it much easier to add to a selection without moving your hands. But then you’re pretty limited in visual mode as far as what you can DO with that selection.

0 Likes

#3

Have you tried a custom key binding? This might work.

[code]{ “keys”: “i”], “command”: “enter_insert_mode”,
“context”:

        {"key": "setting.command_mode"},
        { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": false }
  ]
}[/code]
0 Likes

#4

[quote=“skuroda”]Have you tried a custom key binding? This might work.

[code]{ “keys”: “i”], “command”: “enter_insert_mode”,
“context”:

        {"key": "setting.command_mode"},
        { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": false }
  ]
}[/code][/quote]

Wow. “Might work”? Did you just wing that? I pasted it straight into my user keybindings file and it works without any modification. Most of the values you use in the “context” section are not documented on the web pages I’ve seen on keybindings. Could you point me toward an explanation of that material?

Thanks a billion. Bringing my selection back with me from Visual mode makes life so much better.

0 Likes

#5

“Might work” was because I didn’t test it very well. For context, I skimmed through the vintage key bindings and use docs.sublimetext.info/en/latest/ … -a-context. When I was trying to learn a bit more about context, I also looked through the default key bindings as there are a number of context entries in there. :smile:

Hope that helps.

0 Likes

#6

So, this is amazing, hooray!

But, I’d like to learn about this crazy sublime key bind magic, and I’m having a tough time understanding the logic that makes this work.

Is it the “match_all” that makes it also work when the selection is empty?

I will also take this time to point out that you may want to not use “i” to bind that, as “i” in the context of a visual selection (in vim and vintage) is actually for selecting the inside of some thing (“a” for tag, “b” for parens, “B” for brackets, and all those keys like ", (, {, , etc.), which is highly useful.

Since what we’re looking at here is switching from vim-behavior to sublime-behavior (transitioning from the vintage visual mode to insert mode while keeping the selection alive) it would make more sense to bind it to another key.

I wonder what a good key for that would be. Hmmm. Well, technically anything other than “a” or “i” should be good because of how ST binds expose more State Machine guts than Vim does, and the state here is “vi_can_enter_text_object”.

Sublime binds can be made to work much more precisely because of this.

I’m going to use “e” for “edit”.

0 Likes