16

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?

Felix D.
  • 2,180
  • 1
  • 23
  • 37
  • +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 May 28 '14 at 17:44

3 Answers3

12

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...

joefromct
  • 1,506
  • 13
  • 33
11

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)

Dan
  • 5,209
  • 1
  • 25
  • 37
  • 1
    Glad to help. Incidentally, take a look at this thread for some additional options alongside `nav-mode`: http://superuser.com/questions/695256/file-management-in-emacs – Dan May 22 '14 at 12:16
  • 1
    Nice! I'll take a look cause of course it bugs me a little bit to leave the evil-mode while navigating through files :P I'm such a princess when it comes to my editor haha – Felix D. May 22 '14 at 12:27
  • Here's an example to do it for many modes in the same time: http://wikemacs.org/index.php/Evil#Enter_an_emacs_mode_in_a_given_state – Ehvince May 28 '14 at 09:17
  • Thank you so much for this! I've been searching for ages! I was about to advice a bunch of functions :D – Alberto Zaccagni Aug 11 '14 at 22:04
7

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.

jdhao
  • 24,001
  • 18
  • 134
  • 273
Spacemoose
  • 3,856
  • 1
  • 27
  • 48