tom
tom

Reputation: 553

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):

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?

Upvotes: 4

Views: 2309

Answers (4)

Ehvince
Ehvince

Reputation: 18375

  • 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)

Upvotes: 7

Veen
Veen

Reputation: 33

The solution I use to get around this difficulty when I'm editing prose is to use:

f.

and

F.

It's not as elegant as Vim's sentence motion, but it does the trick. You can also use the "t" commands if you don't want the cursor to end up exactly on the full stop. Like other motion commands, it can be combined with other keystrokes for deleting or whatever else you want to do.

Upvotes: 1

Kai von Fintel
Kai von Fintel

Reputation: 181

Coming to this late, but the answer is that Evil uses emacs' definition of a sentence, which is not the same as vim's. To get close to vim's version, set the sentence-end-double-space to nil:

(setf sentence-end-double-space nil)

The Emacs Manual warns:

If you want to use just one space between sentences, you can set the variable sentence-end-double-space to nil to make the sentence commands stop for single spaces. However, this has a drawback: there is no way to distinguish between periods that end sentences and those that indicate abbreviations. For convenient and reliable editing, we therefore recommend you follow the two-space convention.

Upvotes: 2

Andreas Röhler
Andreas Röhler

Reputation: 4804

Think having two children, would you ask one of them being the way excellent the other is?

WRT Emacs, forget keys, forget vi-mimicry, start with commands. If a command is bound to a key, Emacs will tell you afterward, no need to learn it explicitly.

The clue of Emacs is it's extensibility. Try M-x kill-sentence RET. Doesn't act the way you want? Come back here with a request for change, you will have it in a minute or two :-)

Upvotes: 1

Related Questions