15
votes

I'm trying to get something like Nerd Tree in Emacs and found Nav, which is like the basic emacs file navigator, and it suits me.

The problem is, when I open Nav and switch to its buffer, evil-mode is still on and I have to press C-z if I want to use any Nav specific commands (e.g. . for nav-toggle-hidden-files). And it annoys me.

It's been a few hours I'm trying to fix that issue, by pasting

(require 'evil)
    (evil-mode 0)

everywhere in the Nav files, but obviously I'm doing it wrong.. And I'm pretty sure it will happen again while using other plugins.. How do I do that?

3
+1 on the question. This is one of the reasons my transition from vim-> emacs+evil has been so rocky... is just getting acclimated to a new projects directory structure before i have it memorized with helm/ido. - joefromct

3 Answers

12
votes

As described on the evil wiki here you might want to check out evil-set-initial-state.

Here's the relevant part of my emacs config:

(evil-set-initial-state 'ibuffer-mode 'normal)
(evil-set-initial-state 'bookmark-bmenu-mode 'normal)
(evil-set-initial-state 'dired-mode 'emacs)
(evil-set-initial-state 'sunrise-mode 'emacs)

Doesn't alleviate the fact that I sure would like to have vim key bindings in these modes someday however...

11
votes

You want nav-mode buffers to open in Emacs state rather than in Evil's normal state. I don't know what nav-mode is actually called, but do the following, adjusting the name of the mode accordingly:

(add-to-list 'evil-emacs-state-modes 'nav-mode)

7
votes

What you need is "hook", which will tell Emacs under which conditions you want a particular mode to be active or not.

I don't use evil or nav modes, but you want something very similar to the following line in your .emacs:

(add-hook 'nav-mode-hook 'turn-off-evil-mode)

This command tells Emacs that when the mode (whose hooks are listed in nav-mode-hook) is active, run the function turn-off-evil-mode. You will likely have to modify either the hook list name, or the callback function name according to how nav-mode and evil-mode are implemented.

nav-mode-hook is my guess at what nav-mode will call its hook list. If it doesn't work, check the nav-mode documentation, look for how to add hooks.