Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require 'evil)
- (evil-mode)
- (global-evil-leader-mode)
- (global-evil-mc-mode)
- (setq
- evil-esc-delay 0
- evil-regexp-search t
- evil-vsplit-window-right t
- evil-leader/in-all-states t
- evil-leader/no-prefix-mode-rx '("dired-mode")
- )
- (defmacro define-evil-keys (defs)
- `(cl-loop for (states bind fn) in ,defs
- do (cl-loop for state across (symbol-name states)
- do (define-key
- (cl-case state
- (?n evil-normal-state-map)
- (?v evil-visual-state-map)
- (?m evil-motion-state-map)
- (?i evil-insert-state-map))
- bind
- fn))))
- (define-evil-keys `((nvm " " evil-ex)
- (nm "s" evil-window-next)
- (nm "(" evil-previous-open-brace)
- (nm ")" evil-next-close-brace)
- (m "gf" icicle-find-file) ; motion state doesn't have this by default, oddly
- ))
- (evil-leader/set-leader "," nil)
- (evil-leader/set-key
- "b" #'switch-to-buffer
- "B" #'ibuffer
- "e" #'eval-expression
- "n" #'make-frame
- "o" #'occur
- "ss" #'smerge-mode
- "sn" #'smerge-next
- "sp" #'smerge-prev
- (kbd "s RET") #'smerge-keep-current
- "so" #'smerge-keep-other
- )
- (defmacro init/evil-setup-bindings-aux (mode state &rest bindings)
- (let ((mode-map (intern (concat (symbol-name mode) "-map"))))
- `(progn
- (evil-set-initial-state ',mode ',state)
- ,@(cl-loop for (key binding) in bindings
- collecting `(evil-define-key ',state ,mode-map ,key ,binding)))))
- (defmacro init/evil-setup-bindings (mode state &rest bindings)
- `(init/evil-setup-bindings-aux ,mode ,state
- (" " 'evil-ex)
- ("s" 'evil-window-next)
- ("gg" 'evil-goto-first-line)
- ("G" 'evil-goto-line)
- ("gf" 'icicle-find-file)
- ,@bindings))
- (init/evil-setup-bindings ibuffer-mode motion
- ((kbd "RET") 'ibuffer-visit-buffer))
- (init/evil-setup-bindings Custom-mode motion)
- (init/evil-setup-bindings package-menu-mode motion)
- (init/evil-setup-bindings dired-mode emacs
- ("j" 'dired-next-line)
- ("k" 'dired-previous-line)
- ("/" 'evil-search-forward))
- (init/evil-setup-bindings compilation-mode motion
- ("r" 'recompile))
- ;; jk -> Esc mapping from https://zuttobenkyou.wordpress.com/2011/02/15/some-thoughts-on-emacs-and-vim/ (ctrl-f cofi)
- (define-key evil-insert-state-map "j" #'cofi/maybe-exit)
- (evil-define-command cofi/maybe-exit ()
- :repeat change
- (interactive)
- (let ((modified (buffer-modified-p)))
- (insert "j")
- (let ((evt (read-event nil nil 0.5)))
- (cond
- ((null evt) (message ""))
- ((and (integerp evt) (char-equal evt ?k))
- (delete-char -1) ; delete k
- ;; for c/c++, don't leave whitespace-only lines (TODO: figure out a better approach here since esc doesn't do this)
- (when (and (or (eq major-mode 'c-mode) (eq major-mode 'c++-mode))
- (string-match "^[ \t]+$" (thing-at-point 'line)))
- (beginning-of-line)
- (kill-line))
- (set-buffer-modified-p modified)
- (push 'escape unread-command-events))
- (t (setq unread-command-events (append unread-command-events
- (list evt))))))))
Add Comment
Please, Sign In to add comment