Sublime Forum

How can I make keybindings which only work in normal mode in neovintageous?

#1

I would like to know how I could make keybindings which only work in normal mode (I am using neovintageous).
E.g:
Here I have a keybinding:

{ "keys": ["ctrl+p"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },

This keybinding works in all modes when I enable neovintageous, I only want it to work when I am in normal mode.

0 Likes

#2

There is also vi_command_mode_aware context from

0 Likes

#3

I have now added this "context": [{"key": "vi_normal_mode_aware"}] to my keybinding so It now looks like this:

	{ "keys": ["ctrl+p"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true}, "context": [{"key": "vi_normal_mode_aware"}] },

However, Ctrl+p still works in all of the modes, I only want it to work in normal mode.

0 Likes

#4

I guess you have to nullify the builtin one as well. Otherwise if your command doesn’t match, the builtin matches.

What if

	{ "keys": ["ctrl+p"], "command": "noop" }, // you may have to ensure this command exists
	{ "keys": ["ctrl+p"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true}, "context": [{"key": "vi_normal_mode_aware"}] },
0 Likes

#5

Whenever I press, Ctrl+p with the code the keybindings you have specified, sublime runs the following commands:

command: noop
command: noop
command: noop

If I replace noop with another command such as goto_definition it just runs goto_definition instead.
When I was reading the documentation, I couldn’t find anything about vi_normal_mode_aware, I just assumed that it exists. Perhaps this could be causing the problem? If so, I’m not sure of any other way to bind a keybinding only in normal mode.

0 Likes

#6

I didn’t notice that you use vi_normal_mode_aware. There is no vi_normal_mode_aware. Yet, what’s “normal” mode?

0 Likes

#7

Is there any other way to bind a keybinding in normal mode? (Normal mode is the default mode which neovintageous starts { the one that you have to press hjkl to move around in}).

0 Likes

#8

Then that’s command mode.

0 Likes

#9

Thnx I’ll try that.

0 Likes

#10

It still doesn’t work after I replaced vi_normal_mode_aware with vi_command_mode_aware

0 Likes

#11
    { "keys": ["ctrl+p"], "command": "noop" }, // you may have to ensure this command exists
    { "keys": ["ctrl+p"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true}, "context": [{"key": "vi_command_mode_aware"}] },

Works on my side. Most likely you have no noop command on your setup. Which is a builtin as of ST 4134. So you have to create your own noop command if you are before that.

import sublime_plugin

class NoopCommand(sublime_plugin.ApplicationCommand):
    pass
2 Likes