4

In Emacs I can go one word forward and backward by using M-f and M-b but if I have to go three words backwards or forward I need to repeat the previous sequence three times which seems inelegant. What is the Emacs equivalent of the word-motion concept in Vim? For example, in Vim I can move forward by two words by issuing 2w and backwards by issuing 2b while I am in command mode.

  1. What are the equivalent commands in Emacs for moving between words (more than one at a time)?
  2. Actually I would like go to particular word and change it also. In Vim I can do this via ciw (change in-line word). What would be the equivalent command in Emacs?
1
  • Just came across change-inner.el which brings vim's ci (and co) to Emacs. The package is available from MELPA and can be package-installed. Commented May 17, 2014 at 8:49

1 Answer 1

7

You can use universal-argument. There are two ways to move 3 words forward:

  • C-u3M-f
  • C-3M-f

But that's usually slower than doing M-f 3 times. You know you don't have release M, right?

I do not know what vim's civ does, but to go to a word just search for it with C-s. If you like to jump around have a look at Ace Jump. It works like the follow links feature of browser plugins like vimperator. With it you can jump to lines, word or even chars.


Ok, I don't think there is a built-in for that. Maybe this function helps:

(defun delete-word-at-point () "Delete word at point." (interactive) (let* ((p (point)) (beg (+ p (skip-syntax-backward "w_"))) (end (+ beg (skip-syntax-forward "w_")))) (kill-region beg end))) 

Put it in your ~/.emacs and bind to where you would like it. Maybe M-.:

(global-set-key (read-kbd-macro "M-.") 'delete-word-at-point) 
Sign up to request clarification or add additional context in comments.

2 Comments

ciw is "change inner word", which erases the word under the cursor and puts you into insert mode to type a new one.
I'd rather do backwards-word, then kill-word (less instructions). Also, probably, you don't want to bind to M-. because it's usually for moving to the declaration of the thing you are looking at. Maybe use M-r - that's the command I never find any use for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.