NeoTree

A emacs tree plugin like NERD tree for Vim.

https://github.com/jaypei/emacs-neotree

About

https://raw.githubusercontent.com/wiki/jaypei/emacs-neotree/imgs/neotree-1.png

Installation

Clone project:

  $ cd /some/path
  $ git clone https://github.com/jaypei/emacs-neotree.git neotree

Add config to emacs:

  (add-to-list 'load-path "/some/path/neotree")
  (require 'neotree)
  (global-set-key [f8] 'neotree-toggle)

Open (toggle) NeoTree:

  <F8>

Usage

Shortcut (Only in Neotree Buffer)

Commands(Global)

Command(Only in NeoTree Buffer)

Useful tips

neo-smart-open

Every time when the neotree window is opened, let it find current file and jump to node.

    (setq neo-smart-open t)

Work with Projectile

When running ‘projectile-switch-project’ (C-c p p), ‘neotree’ will change root automatically.

   (setq projectile-switch-project-action 'neotree-projectile-action)

find-file-in-project

If you use the find-file-in-project (ffip) library, you can open NeoTree at your directory root by adding this code to your .emacs.d:

  (defun neotree-project-dir ()
    "Open NeoTree using the git root."
    (interactive)
    (let ((project-dir (ffip-project-root))
          (file-name (buffer-file-name)))
      (if project-dir
          (progn
            (neotree-dir project-dir)
            (neotree-find file-name))
        (message "Could not find git project root."))))
  
  (define-key map (kbd "C-c C-p") 'neotree-project-dir)

Projectile

Similar to find-file-in-project, NeoTree can be opened (toggled) at projectile project root as follows:

  (defun neotree-project-dir ()
    "Open NeoTree using the git root."
    (interactive)
    (let ((project-dir (projectile-project-root))
          (file-name (buffer-file-name)))
      (neotree-toggle)
      (if project-dir
          (if (neo-global--window-exists-p)
              (progn
                (neotree-dir project-dir)
                (neotree-find file-name)))
        (message "Could not find git project root."))))
 (global-set-key [f8] 'neotree-project-dir)

Use with evil mode

If you use evil-mode, by default some of evil key bindings conflict with neotree-mode keys. For example, you cannot use q to hide NeoTree. To make NeoTree key bindings in effect, you can bind those keys in evil-normal-state-local-map in neotree-mode-hook, as shown in below code:

    (add-hook 'neotree-mode-hook
              (lambda ()
                (define-key evil-normal-state-local-map (kbd "TAB") 'neotree-enter)
                (define-key evil-normal-state-local-map (kbd "SPC") 'neotree-quick-look)
                (define-key evil-normal-state-local-map (kbd "q") 'neotree-hide)
                (define-key evil-normal-state-local-map (kbd "RET") 'neotree-enter)
                (define-key evil-normal-state-local-map (kbd "g") 'neotree-refresh)
                (define-key evil-normal-state-local-map (kbd "n") 'neotree-next-line)
                (define-key evil-normal-state-local-map (kbd "p") 'neotree-previous-line)
                (define-key evil-normal-state-local-map (kbd "A") 'neotree-stretch-toggle)
                (define-key evil-normal-state-local-map (kbd "H") 'neotree-hidden-file-toggle)))

In recent versions of evil-mode you can create key bindings for specific modes using evil-define-key, so another way to override mappings in neotree-mode is as shown below:

    (evil-define-key 'normal neotree-mode-map (kbd "TAB") 'neotree-enter)
    (evil-define-key 'normal neotree-mode-map (kbd "SPC") 'neotree-quick-look)
    (evil-define-key 'normal neotree-mode-map (kbd "q") 'neotree-hide)
    (evil-define-key 'normal neotree-mode-map (kbd "RET") 'neotree-enter)
    (evil-define-key 'normal neotree-mode-map (kbd "g") 'neotree-refresh)
    (evil-define-key 'normal neotree-mode-map (kbd "n") 'neotree-next-line)
    (evil-define-key 'normal neotree-mode-map (kbd "p") 'neotree-previous-line)
    (evil-define-key 'normal neotree-mode-map (kbd "A") 'neotree-stretch-toggle)
    (evil-define-key 'normal neotree-mode-map (kbd "H") 'neotree-hidden-file-toggle)

popwin

If you use popwin, when NeoTree is open and successively a temporary buffer is opened with popwin, a new window with the NeoTree buffer is displayed side by side next to the first one (#50). This code will help you:

  (when neo-persist-show
    (add-hook 'popwin:before-popup-hook
              (lambda () (setq neo-persist-show nil)))
    (add-hook 'popwin:after-popup-hook
              (lambda () (setq neo-persist-show t))))

ChangeLog

0.2

0.1.5: (2014-06-05)

0.1.4: (2014-05-27)

0.1.3: (2014-04-13)

0.1.2: (2014-04-08)

0.1.1: (2014-04-06)

Basic Functionalities.