   (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)))))
+  (evilified-state--setup-normal-state-keymap)
+  (evilified-state--setup-visual-state-keymap)
+  (add-hook 'pre-command-hook 'evilified-state--pre-command-hook nil 'local)
+  (add-hook 'evil-visual-state-entry-hook
+            'evilified-state--visual-state-on-entry nil 'local)
+  (add-hook 'evil-visual-state-exit-hook
+            'evilified-state--visual-state-on-exit nil 'local))
 
 (defun evilified-state--evilified-state-on-exit ()
   "Clean evilified state"


(defun evilified-state--visual-state-on-entry ()
  "Setup visual state."
  (add-hook 'pre-command-hook 'evilified-state--pre-command-hook nil 'local))

(defun evilified-state--visual-state-on-exit ()
  "Clean visual state"
  (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)

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

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

(defvar evilified-state--modes nil
  "List of all evilified modes.")

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