 (defvar evilified-state--modes nil
   "List of all evilified modes.")
 
-(defvar evilified-state--visual-state-map evil-visual-state-map
-  "Evil visual state map backup.")
-
 (defvar evilified-state--evil-surround nil
   "Evil surround mode variable backup.")
 (make-variable-buffer-local 'evilified-state--evil-surround)
+
+(defvar evilified-state--normal-state-map nil
+  "Local backup of normal state keymap.")
+(make-variable-buffer-local 'evilified-state--normal-state-map)
 
 (evil-define-state evilified
   "Evilified state.

  (when (bound-and-true-p evil-surround-mode)
    (make-local-variable 'evil-surround-mode)
    (evil-surround-mode -1))
  (setq-local evil-normal-state-map (copy-keymap evil-normal-state-map))
  (define-key evil-normal-state-map [escape] 'evil-evilified-state)
  (setq-local evil-visual-state-map
              (cons 'keymap (list (cons ?y 'evil-yank)
                                  (cons 'escape 'evil-exit-visual-state)))))

(defun evilified-state--evilified-state-on-exit ()
  "Clean evilified state"


(defun evilified-state--visual-state-on-entry ()
  "Setup visual state."
  ;; we need to clear temporarily the normal state keymap in order to reach
  ;; the mode keymap
  (when (eq 'evilified evil-previous-state)
    (evilified-state--clear-normal-state-keymap))
  (add-hook 'pre-command-hook 'evilified-state--pre-command-hook nil 'local))

(defun evilified-state--visual-state-on-exit ()
  "Clean visual state"
  (when (eq 'evilified evil-previous-state)
    (evilified-state--restore-normal-state-keymap))
  (remove-hook 'pre-command-hook 'evilified-state--pre-command-hook 'local))

(add-hook 'evil-evilified-state-entry-hook
          'evilified-state--evilified-state-on-entry)
(add-hook 'evil-evilified-state-exit-hook
          'evilified-state--evilified-state-on-exit)

;; default key bindings for all evilified buffers
(define-key evil-evilified-state-map "/" 'evil-search-forward)
