rust-lang / rust-enhanced

The official Sublime Text 4 package for the Rust Programming Language
MIT License
785 stars 105 forks source link

Single quote ' gets typed even in Vim command mode #185

Open lord opened 7 years ago

lord commented 7 years ago

Sublime Text Version

Sublime Text 3 (Build 3126)

Rust Enhanced Version

1.3.2

Operating system

macOS 10.12.4

Expected behavior

When I type 'm in command mode in Vim mode, I expect to be able to jump to a bookmark made previously with 'mm'.

Actual behavior

Instead, the ' is typed literally. This may be because of the snippet in #26 that prevents Sublime from making a second close single quote?

Sorry if this was already fixed and I somehow haven't updated my Rust Enhanced — I've got a weird Sublime setup somehow! Thanks for the awesome plugin <3

Steps to reproduce

  1. Enable Vim mode
  2. Press the ' key while in command mode

References

SCdF commented 5 years ago

A workaround here is just to over-ride this particular keybinding and put it back to whatever your Vi plugin uses.

For example, I use NeoVintageous, and so I added the following to my keybindings:

 {"keys": ["'"], "command": "_nv_feed_key", "args": {"key": "'"}, "context": [{"key": "vi_command_mode_aware"}]},

And normal mode works as intended on Rust files again.

LPGhatguy commented 4 years ago

I'm interested in contributing a fix to this. Is there a known way for Sublime plugins to play nice when trying to override keybinds like this without needing the NeoVintageous plugin to explicitly acknowledge Rust Enhanced or vice-versa?

ehuss commented 4 years ago

You can try something like this:

diff --git a/Default.sublime-keymap b/Default.sublime-keymap
index 337e78b..fb033ac 100644
--- a/Default.sublime-keymap
+++ b/Default.sublime-keymap
@@ -1,7 +1,11 @@
 [
     // Disable auto-pair for single quote since it is often used for lifetimes.
     { "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'"}, "context":
-        [{ "key": "selector", "operator": "equal", "operand": "source.rust" }]
+        [
+            { "key": "selector", "operator": "equal", "operand": "source.rust" },
+            // Ignore this binding in Vintage command mode.
+            { "key": "setting.command_mode", "operand": false }
+        ]
     },
     // ' in b'c' will skip past the end quote.
     { "keys": ["'"], "command": "move", "args": {"by": "characters", "forward": true}, "context":

I don't use vi mode, so I don't really know if it works properly. This might need to be done for the other key bindings. You might also try asking on the sublime forum to see if there are other ideas on how to handle this.