Question

I'm using the wonderful evil package for vim bindings in emacs.

The one key that is not right is Ctrl+U. It is still the emacs prefix, rather than "up".

Does anybody have a solution for that in some lisp code for my .emacs?

Thanks.

Was it helpful?

Solution

there is a variable that you can add to your .emacs

(setq evil-want-C-u-scroll t)

it needs to appear before the call to (require 'evil).

OTHER TIPS

Alternatively, it's easy enough to define your own keybindings, and the evil API is rich enough to make it super easy:

(define-key evil-normal-state-map (kbd "C-u") 'evil-scroll-up)
(define-key evil-visual-state-map (kbd "C-u") 'evil-scroll-up)
(define-key evil-insert-state-map (kbd "C-u")
  (lambda ()
    (interactive)
    (evil-delete (point-at-bol) (point))))

I had to go this route as evil-want-C-u-scroll wasn't functioning correctly for me.

In order to get bling's answer to work for anyone useing John Wiegley's use-package, make sure you define it in the :init section, like so:

(use-package evil
 :ensure t
 :init
 (setq evil-want-C-u-scroll t)
 :config
 (evil-mode 1)
 ;; snip...
)

HTH

Vim's C-u is half-screen page up. I replicated it using the following,

(define-key evil-normal-state-map (kbd "C-u") 'evil-scroll-up)

From C-h f evil-scroll-up,

(evil-scroll-up COUNT)

Scrolls the window and the cursor COUNT lines upwards. The default is half the screen.

The vim's C-u is not 'previous-line, it's more like page up. I don't know how to replicate the exact behavior, but you could just try C-b (evil-scroll-page-up) or map C-k, C-j to go up/down 10 lines.

(global-set-key (kbd "C-k") (lambda () (interactive) (previous-line 10)))
(global-set-key (kbd "C-j") (lambda () (interactive) (next-line 10)))

The C-u key is also quite important to Emacs so you probably shouldn't overwrite it anyway.

To add to melleb's answer, I also defined the key combination when evil-want-C-u-scroll:

(use-package evil
:ensure t
:init
(setq evil-want-C-u-scroll t)

(when evil-want-C-u-scroll
   (define-key evil-insert-state-map (kbd "C-u") 'evil-scroll-up)
   (define-key evil-normal-state-map (kbd "C-u") 'evil-scroll-up)
   (define-key evil-visual-state-map (kbd "C-u") 'evil-scroll-up)
   (define-key evil-motion-state-map (kbd "C-u") 'evil-scroll-up))

:config
(evil-mode 1)
...
)

This works for GNU Emacs 24.4.1

First, to answer your question:

(define-key evil-insert-state-map  "\C-u" 'previous-line)
(define-key evil-normal-state-map  "\C-u" 'previous-line)
(define-key evil-replace-state-map "\C-u" 'previous-line)
(define-key evil-visual-state-map  "\C-u" 'previous-line)
(define-key evil-motion-state-map "\C-u" 'previous-line)

Since I can't really test myself (no evil), try maybe the following if those do not work:

Replace

(define-key evil-motion-state-map "\C-u" 'previous-line)

With

(define-key evil-motion-state-map "cu" 'previous-line)

Do this for whichever mode of evil you want it/it is neccessary.

Furthermore, maybe there is an "evil" version of up, you might want to bind that instead.

Also, correct me if I am wrong, but I am pretty sure evil 'ships' with a functional/useful "up" somewhere in those keybindings, maybe read up on it somewhere.

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