CI inconsistency

I find ci behaviour a bit confusing.
When doing ci" and my cursor is in front of the ", it goes inside the "" and works as expected.
When I do ci{ and my cursor is in front it does nothing, I need to have my cursor on the first or last { for it to work as I want.
Now I read an explanation that vim doesn’t necessarily expects " to come in a pair and I can’t get that. It’s weird.
(Here’s where I read it:
I find it weird because if I do -change inside- it means there’s something to open and something to close.
Also: if I have a longer paragraph inside two ", ci doesn’t want to work…
If the same paragraph is inside brackets, it works as expected.

Reading that article it does make sense that Vim’s pair matching struggles to match pairs of ". It’s not that logically it doesn’t know open quote - close quote. It that both open and close quotes are identical, unlike open bracket - close bracket which face different ways visually (and have difference keys ASCII parameters in terms of data).

With ci" it has to work out if it is looking at a the opening " or the closing " before it can change anything. It has a stab, but without lots of scanning left and right, particularly with long strings, it may get it wrong.

As for the cursor placement, its not an issue I have so cannot comment.

1 Like

So first up, remember that i goes with a few things: ci, vi, di, and yi off the top of my head.

Next, yes, i as used for inside is inconsistent, like you see me do in the book. I believe there’s a way to fix it, but for the most part it works with only a few bounding characters.

I did Vim School Ep. 3 yesterday and thought I’d post this here:

You can easily make ci( work with this mapping:

nnoremap <silent> ci( f)ci(

Likewise for [.

By the way, @zedshaw, this course is another great learning resource! Thanks for making it available.

Edit: Make it a closing parenthesis so it doesn’t jump to the next pair on the line from inside a pair.


Yeah I would have never have bothered with Vim had it not been for Vim School. It was really good fun, especially learning about Ed etc.

A free service run by Zed A. Shaw for