5

When doing the command ci" Vim will edit the text inside the next quoted string on the line, even if the cursor is outside the quotation marks. However, when doing ci( it only works if the cursor is being situated inside the parenthesizes.

Why? Can ci( be made to jump to the first occurence of ( as ci" does?

Sample text (using Erlang syntax) where I'm playing around:

    ?assertEqual({200, "OK"}, status(FirstResponse)),
%   ^
%   Here I'm expecting  ci(  to jump in to the parenthesis ( ci"  works)
1
  • I hope you don't mind, but I edited your question to include only the relevant line of code exhibiting the problem.
    – Prince Goulash
    Commented Sep 7, 2011 at 9:50

3 Answers 3

5

Following a quick look at the documentation (help v_aquote, help v_iquote), I am inclined to say that this is a bug in ci", rather than a deficiency in ci(. The observed ci( behaviour is consistent with ci{ and ci[.

That said, you can get the desired behaviour of ci( with this mapping:

nnoremap ci( f(ci(

--- EDIT ---

--- (This question has been migrated to superuser, which I am not a member of)

The following function/mapping has different behaviour depending on whether a preceding ( is detected. It solves the (a) (b) problem with my original mapping (as pointed out in the comments). It still may not be perfect though...

function New_cib()
    if search("(","bn") == line(".")
        sil exe "normal! f)ci("
        sil exe "normal! l"
        startinsert
    else
        sil exe "normal! f(ci("
        sil exe "normal! l"
        startinsert
    endif
endfunction

nnoremap ci( :call New_cib()<CR>
nnoremap cib :call New_cib()<CR>
5
  • 2
    This has one drawback, when being inside one parenthesis, the command jumps to the next: (|a) (b) where | is the cursor position. So it kind of breaks the behavior of ci( in that particular case. Commented Sep 7, 2011 at 9:59
  • @Adam: very good point, thanks. I thought the solution was to search forward for the closing parenthesis: f)ci(, but then the wrong brackets will be selected in your original question. Looks like a more complex general solution is necessary.
    – Prince Goulash
    Commented Sep 7, 2011 at 10:18
  • @Prince: Unfortunately. :-( Commented Sep 7, 2011 at 10:37
  • I'll mark this as accepted since it has a partial solution that might work for someone. +1 for learning f(. Commented Sep 8, 2011 at 7:25
  • I am not sure why this has been moved to superuser, but I have signed up and edited my answer to include a fuller solution. Commented Sep 8, 2011 at 8:12
5

The reason is: brackes, angle brackets and braces go by pairs. Therefore, they can nest.

Single and double quotes generally cannot nest (except in bash scripts with "$("something")" syntax, so it is allowed to find a text object even if the cursor is not inside it, because there cannot be any outside object.

1
  • 2
    Although a useful property would to be, if no outer scope is found, the next on the line could be chosen? Commented Sep 7, 2011 at 10:17
1

I think " is the only text objects that work that way, i.e. select the next matching pattern on the line.

The help might explain why :

a"                          *v_aquote* *aquote*
a'                          *v_a'* *a'*
a`                          *v_a`* *a`*
        "a quoted string".  Selects the text from the previous
        quote until the next quote.  The 'quoteescape' option
        is used to skip escaped quotes.
        Only works within one line.
        When the cursor starts on a quote, Vim will figure out
        which quote pairs form a string by searching from the
        start of the line.
        Any trailing white space is included, unless there is
        none, then leading white space is included.
        When used in Visual mode it is made characterwise.
        Repeating this object in Visual mode another string is
        included.  A count is currently not used.

Apparently Vim try to find out the quoted text by searching from the start of the line. So it does not matter where you are on the line. (However it does not seems to work when your cursor is after the quoted text)

1
  • 1
    I still think this is a bug in ci" because the cursor does not start on a quote, so the case given in the documentation does not apply.
    – Prince Goulash
    Commented Sep 7, 2011 at 9:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .