Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs equivalent of Vim's word motion and change in-line word

Tags:

vim

emacs

editing

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?
like image 303
Geek Avatar asked Mar 22 '23 22:03

Geek


1 Answers

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)
like image 160
ahilsend Avatar answered Mar 25 '23 12:03

ahilsend