Search code examples
vimemacsclojureevil-mode

Evil Emacs mode: sentence motions and other questions


I love vim. It gives me the feeling that I am reaching directly into the text and bending it to my will.

That said. I also like Clojure, and Clojurescript, and Lisp, and Org-mode. I really, really tried to like Emacs, in Evil mode, and I gave it 6-8 weeks before I gave up in frustration.

I'm considering trying again, because I've seen some really great examples of Literate Programming using ractive.js and org-mode. But I want to plan ahead this time. I have a short list of things that I want to know how to do before I just charge in willy-nilly (if, in fact, I am brave enough to go for it again):

  • Sentence and paragraph motions. I write some code, but I write much more plain text. As I edit I'm usually changing/deleting through the end of a sentence or two. I could not get this to work in evil mode, and iirc there was even a flag to set that seemed to suggest it was possible, but I could not get it to work. Has evil figured this motion out yet? If not, how would I tell it about this motion?
  • Leader maps and meta-efficiency maps. I didn't really start to get awesome in vim until I found out about leader maps and maps for making maps. Nothing too insane--I just created a map to open my .vimrc, and set up a few abbreviations in .vim files, so that I had a permanent map within seconds of realizing I needed it. What might the equivalent technique in emacs be? How can I make maps in a vim-ish (i.e., minimal chording) way? Is it ilisp or bust for me?
  • Buffer commands. I didn't quite get the logic of there being 2-4 chords in order to change what file you were working on. I'm willing to learn--it's not like I really used vim buffers, I just kept opening files inefficiently--but it'd be nice to find a tutorial that isn't convincing me to type in the vim way when I'm going to be on the path of evil.

Editor wars are silly, emacs has a lot going for it, but I like home row! Is there a way I can get the power of the emacs operating system while keeping this decent editor I've learned?


Solution

    • sentence and paragraph motion: I suggest you give some example commands that didn't suit your needs. I'm happy with evil's motion keys.
    • leader maps: http://wikemacs.org/index.php/Evil that doc should show you how to do things with emacs. Defining keys look like the following:

      (define-key evil-normal-state-map "q" 'ido-kill-buffer) ; was previously record macro
      

      Also be sure to read the official pdf doc. Also look at the examples of key-chord mode.

    • buffer commands: true, managing buffers should be quicker. Do you know ido-mode ? Here's how I use a combination of key-chord and ido:

      (key-chord-define-global "'b" 'ido-switch-buffer)
      

      and I have similar keys for next-buffer and previous-buffer. I think it's much quicker than finding the file path on a terminal to launch vim. Also I can't do without projectile to find new files: https://github.com/bbatsov/projectile

    Now do you have more precise question ?

    edit: on going to the end of a sentence:

    So, evil uses evil-forward-sentence but yes, it doesn't have the same behaviour than in vim (see comment). Emacs has forward-sentence but it has the same behaviour. I couldn't find a function with the desired effect.

    forward-sentence is based on the sentence-end variable (see it with M-x ielm), which is a regexp defining end of lines. So it's possible to re-define it. Here's a simple example that needs to be extended:

        (setq sentence-end "[\\.\\?\\!] +") ;; . or ? or ! followed by spaces.
    

    now forward-sentence will stop at the next point. We can remap evil's ):

        (define-key evil-normal-state-map ")" 'forward-sentence)