1

I want to disable evil insert key such as a, i, o in read-only mode (keep navigation key such as j and k), my idea is to disable these keys in local buffer when enabling read-only mode and enable these keys after disabling read-only mode.

There are two difficulties for me:

  1. How to disable evil insert key.
  2. How to execute code when enable/disable mode.

I notice there is evil-disable-insert-state-bindings variable. I try to set it to t in local buffer, but a, i keys still work.

I know I can use (add-hook 'read-only-mode-hook (lambda () (message "read-only-mode changed"))) to detect mode change, but I don't know how to distinguish enabling and disabling mode.

1 Answer 1

0

For read-only buffers, Evil provides the Evil specific motion-state (see here). You can configure the modes to open in that state by adding/removing the mode names to the list of evil-motion-state-modes.

If you are using Spacemacs then you can also use the evilified-state in a similar way (or when not using Spacemacs you could try https://github.com/mohsenil85/evil-evilified-state, I guess it works fine, but I have never tested it).

Alternatively, I think I would recommend to just use the very well designed evil-collection, although as a Spacemacs user I haven't used it much myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.