Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Does emacs have the equivalent of VIMs ci" command? Basically I want to replace the text inside a set of quotation marks.

In vim I can ci) or ci] or ci} to "change inner *"...

share|improve this question

8 Answers 8

up vote 14 down vote accepted

Off the top of my head, the closest command is M-z " which deletes everything from point to the next occurance of the " character.

There is also C-M-k, aka "kill balanced expression", which will delete a full parenthesized statement or double quoted string etc. based on the current modes definition of "balanced expression" and the character currently under point (ie. it only works if the cursor is on the opening '"' or '(' etc.).

share|improve this answer

Similarly to Justin's suggestion C-M-SPACE gives you "mark-sexp" which will select to the balancing paren, quote, etc. and then you can C-w or whatever to make it go away. In case you want to SEE what you're about to delete before you delete it...

share|improve this answer

Yes! The equivalent of VIMs ci" command in Emacs is... ci" :-)

share|improve this answer

Just stumbled upon this question; here is a custom solution that's worked for me:

(defun seek-backward-to-char (chr)
  "Seek backwards to a character"
  (interactive "cSeek back to char: ")
  (while (not (= (char-after) chr))
    (forward-char -1)))

(defun delete-between-pair (char)
  "Delete in between the given pair"
  (interactive "cDelete between char: ")
  (seek-backward-to-char char)
  (forward-char 1)
  (zap-to-char 1 char)
  (insert char)
  (forward-char -1))

Then bind delete-between-pair to whatever key you like. For me, I have it bound on C-z i.

share|improve this answer

I'm afraid I don't know about VIM's ci feature, but have you looked at Emacs regexp replace? I can't speak to the exact semantics or how easy it is to use in comparison, but it's what I would use for what I think you want.

share|improve this answer
emacs regexp replace is the equivalent of vi :s/regex/replacement/, what he wants is a keypress to delete and replace the current balanced expression at point. –  Justin Smith Mar 26 '10 at 12:53

I've made a minor mode which provides some of those Vim facilities called Markit.

share|improve this answer

Magnars (author of EmacsRocks site) wrote this plugin to do exactly what you are asking for.


Obviously, you could also use Evil mode.

share|improve this answer

This was something that I was missing from Vim, and zap-to-char didn't seem to cut it right.

Here is my humble attempt to recreate "ci" and "ca":

(defun change-outer (str) (interactive "sChange outer: ") (condition-case nil (search-backward str (line-beginning-position)) (error (search-forward str (line-end-position)) (forward-char -1))) (kill-sexp) )

(defun change-inner (str) (interactive "sChange inner: ") (condition-case nil (search-backward str (line-beginning-position)) (error (search-forward str (line-end-position)) (forward-char -1))) (push-mark) (forward-sexp) (forward-char -1) (exchange-point-and-mark) (forward-char 1) (kill-region (point) (mark)) )

Normally, the condition-case is not necessary, since the third (optional) parameter of search-forward/search-backward is meant to indicate what to do in case the search fails. But for some reason, placing a the second search as the third parameter for the first one yields strange behavior.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.