9

In vim I have this in my .vimrc:

" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

How do I get the easy window nav in evil-mode?

Also, in vim "+ will copy to my system clipboard? This doesn't seem to work in emacs.

$ emacs --version

GNU Emacs 24.3.1 Copyright (C) 2013 Free Software Foundation, Inc. GNU Emacs comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of Emacs under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING.

$ cat .emacs

;;

;; Package manager and better repos
(require 'package)
(add-to-list 'package-archives 
                 '("marmalade" .
                         "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(package-initialize)

(setq backup-directory-alist `(("." . "~/.emacs.d/saves")))

;; Indents, tab as spaces
(setq-default indent-tabs-mode nil)
(setq default-tab-width 2)

;; evil-mode
(eval-after-load "evil"
  '(progn
     (define-key evil-normal-state-map (kbd "C-h") 'evil-window-left)
     (define-key evil-normal-state-map (kbd "C-j") 'evil-window-down)
     (define-key evil-normal-state-map (kbd "C-k") 'evil-window-up)
     (define-key evil-normal-state-map (kbd "C-l") 'evil-window-right)))
(require 'evil)
(evil-mode 1)
;(setcdr evil-insert-state-map nil)
;(define-key evil-insert-state-map [escape] 'evil-normal-state)

;; Fun stuff
(require 'jabber-autoloads)
(require 'jabber)
Justin Thomas
  • 5,680
  • 3
  • 38
  • 63

1 Answers1

12

You can add the key bindings you want to use to evil-normal-state-map:

(eval-after-load "evil"
  '(progn
     (define-key evil-normal-state-map (kbd "C-h") 'evil-window-left)
     (define-key evil-normal-state-map (kbd "C-j") 'evil-window-down)
     (define-key evil-normal-state-map (kbd "C-k") 'evil-window-up)
     (define-key evil-normal-state-map (kbd "C-l") 'evil-window-right)))

Wrapping the code into eval-after-load is necessary to ensure that evil-normal-state-map is defined/available when making the calls to define-key.

If you want to make the same bindings available in other "states" (such as "Motion" state) as well, just add them to the corresponding key maps as shown above (in the case of "Motion" state, the corresponding map is called evil-motion-state-map).


To get Emacs to use the system clipboard, try setting x-select-enable-clipboard to a non-nil value:

(setq x-select-enable-clipboard t)

There are also specific commands for killing and yanking that use the clipboard. From the documentation:

  • clipboard-kill-region:

    Kill the region, and save it in the X clipboard.

  • clipboard-kill-ring-save:

    Copy region to kill ring, and save in the X clipboard.

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
  • M-x evil-window-up works, but C-k etc don't. Get an error when I try to yank text now after setting the x-select-enable-clipboard. – Justin Thomas May 10 '14 at 14:39
  • Since this solution works on my system I can't help you unless you provide more information. Please add the contents of your `.emacs` file to your question. Do you get an error when hitting `C-k`? Also, what's the error you are getting when trying to yank text? Do the alternative commands I listed (`clipboard-kill-region`/`clipboard-kill-ring-save`) work? – itsjeyd May 10 '14 at 15:41
  • Saved it above. I've tried the require evil-mode in several places. Just throwing darts blind folded. – Justin Thomas May 10 '14 at 15:55
  • clipboard-kill-region doesn't save it to the os clipboard. I'm in terminal on Mac. – Justin Thomas May 10 '14 at 16:00
  • [pbcopy](http://marmalade-repo.org/packages/pbcopy) provides "OS X clipboard integration for Emacs". Install it via `M-x package-install RET pbcopy RET`, and delete the configuration related to `x-select-enable-clipboard` from your `.emacs`. – itsjeyd May 10 '14 at 16:14
  • That seems to engage it, but get this error now: Symbol's function definition is void: x-set-selection – Justin Thomas May 10 '14 at 16:39
  • I'm not on a Mac, so I can't debug that for you. You might want to consider asking a separate question for this problem (also because it's not related at all to your main question). – itsjeyd May 10 '14 at 17:37
  • As for your main question, I completely replaced my own config with yours, and I can switch windows using `C-h`/`C-k`/etc. without problems (even in the terminal version of Emacs). What happens when you hit these bindings? Do you get any errors or messages displayed in the echo area (that's the area at the bottom of the Emacs frame)? – itsjeyd May 10 '14 at 17:40
  • Ok, it all works in aquamacs, but not in the terminal one. I guess that will do for now. Thanks for your help! Probably some bs issue with the brew installed terminal one. – Justin Thomas May 10 '14 at 18:35