Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert mode bindings interfere with each other #4353

Closed
wcroughan opened this issue Dec 10, 2019 · 7 comments · Fixed by #4735
Closed

insert mode bindings interfere with each other #4353

wcroughan opened this issue Dec 10, 2019 · 7 comments · Fixed by #4735

Comments

@wcroughan
Copy link

Describe the bug
I have the following line in my .vimrc file:
imap qr
Until recently this has consistently worked. If I typed "qr" in insert mode, the qr would be deleted and I would return to normal mode. Today, about 80% of the time this works, but around 20% of the time this doesn't work. When it doesn't work, it simply types qr and stays in insert mode as if the imap didn't exist.

If it doesn't work, deleting the qr and typing it again usually fixes it (but sometimes fails about 20% of the time, and so on recursively...).

To Reproduce

  1. Add line "imap qr " in .vimrc
  2. Edit a file (I'm editing a .cpp file with ~1800 lines)
  3. In insert mode, begin typing something and then type "qr"

Expected behavior
The imap should be respected, resulting in a return to normal mode as if Esc had been pressed.

Environment (please complete the following information):

  • Extension (VsCodeVim) version: 1.12.2
  • VSCode version: 1.40.2
  • OS: Arch Linux ("lsb_release" gives 1.4)

Other extensions:
Configuration Editing
Node Debug Auto-attach
Emmet
Extension Authoring
Git
JSON Language Features
Merge Conflict
NPM support for VS Code
TypeScript and JavaScript Language Features
C/C++

@J-Fields
Copy link
Member

Does this work if you configure the keybinding via the VSCode settings file rather than a .vimrc?

@wcroughan
Copy link
Author

wcroughan commented Dec 10, 2019

Agh my apologies, I set this up a while ago. The way I've implemented this is actually through the settings.json (User) file. I've pasted the whole file below, the first vim.insertModeKeyBindings is the one that's relevant here.

So to be clear the title is incorrect, this is actually a case of vim.insertModeKeyBindings not working intermittently.
EDIT: I changed the post's title to be correct.

{
	"vim.useSystemClipboard": true,
	"vim.hlsearch": true,
	"vim.insertModeKeyBindings": [
		{
			"before": ["q", "r"],
			"after": ["<Esc>"]
		},
		{
			"before": ["t", "h", "r", "u", "n"],
			"after": ["t", "h", "r", "o", "w", " ", "\"", "U", "n", "i", "m", "p", "l", "e", "m", "e", "n", "t", "e", "d", "\"", ";", " ", "/", "/", "T", "O", "D", "O", " ", "i", "m", "p", "l", "e", "m", "e", "n", "t", "q", "r", "=", "0"]
		}

	],
	"vim.normalModeKeyBindingsNonRecursive": [
		{
			"before": ["<Space>"],
			"commands": [":nohlsearch"]
		}
	],
	"vim.visualModeKeyBindingsNonRecursive": [
		{
			"before": ["/", "/"],
			"commands": ["y", "/", "\\", "V", "<C-R>", "\"", "<CR>"]
		}
	],
	"workbench.startupEditor": "newUntitledFile",
	"editor.detectIndentation": false,
	"files.exclude": {
		"**/build": true,
		"**/output": true
	},
    "C_Cpp.clang_format_path": "/usr/bin/clang-format",
    "editor.formatOnType": true,
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true
}

@wcroughan wcroughan changed the title imap intermittently ignored vim.insertModeKeyBindings intermittently ignored Dec 10, 2019
@J-Fields
Copy link
Member

Thanks for clarifying. Was this working for you in 1.11.3 (the previous version)?

@wcroughan
Copy link
Author

OK after some confusing minutes debugging, it seems the way I originally described the bug was accurate.

I've figured out I actually was both loading my vimrc file (with imap) and loading the above settings.json mappings. I tried removing each one and found that using just the imap from vimrc file has the issue mentioned above, but the keymap through settings.json seems to work fine.

I've updated the post title once again, as it seems the bug as I originally laid it out really exists. But moving the setting to settings.json is a fine workaround for me.

And yes, the way I had it configured worked as I intended in the previous version.

@wcroughan wcroughan changed the title vim.insertModeKeyBindings intermittently ignored imap intermittently ignored Dec 10, 2019
@wcroughan
Copy link
Author

OK it turns out the bug is not random, but is a function of the other vim.insertModeKeyBindings entry! The two bindings I have in my settings.json are triggered by typing "qr" and "thrun". Whenever one of them is possibly in progress, the other will not trigger. For instance, if I type "tqr", the "qr" binding will not be triggered because I started part of the "thrun" binding. Similarly, "thrqr" won't trigger the qr binding, and "qthrun" won't trigger the thrun binding.

Note I spoke too soon in the above post. This bug exists regardless of how the qr mapping is defined. I deleted the qr mapipng from settings.json and added it to the imported vimrc and the same interaction occurs between the qr and thrun bindings.

Sorry this started quite unorganized, but on the bright side I now have a fully reproducible non-random bug (on my machine at least). Please let me know what the best way to organize this is (i.e. should I rename this thread? Close this one and start a new one? Edit my first post to include the information here?).

@J-Fields
Copy link
Member

Nice, thanks for investigating! If you could just edit the title, that'd be awesome

@wcroughan wcroughan changed the title imap intermittently ignored insert mode bindings interfere with each other Dec 10, 2019
@ericharding
Copy link

ericharding commented Dec 24, 2019

Just thought I'd stop by and confirm that I see the same behavior and provide a second repro in case it's useful. (I also thought it was random at first). My settings.json includes the following and in recent versions I can't use "jj" following a space. If I remove the second insertModeKeyBinding then jj works as expected.

"vim.insertModeKeyBindings": [
        {
            "before": [ "j", "j" ],
            "after": [ "<Esc>" ]
        }
        ,
        {
            "before": [ "leader", ";" ],
            "after": [],
            "commands": [
                { "command": "editor.action.commentLine" }
            ]
        }
    ],

@berknam berknam mentioned this issue May 29, 2020
10 tasks
J-Fields pushed a commit that referenced this issue Aug 16, 2020
This is a pretty massive change; see pull request #4735 for full details

Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc

Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants