Question

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)
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top