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.

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)
share|improve this question

migrated from stackoverflow.com Sep 8 '11 at 7:45

This question came from our site for professional and enthusiast programmers.

    
I hope you don't mind, but I edited your question to include only the relevant line of code exhibiting the problem. –  Prince Goulash Sep 7 '11 at 9:50
    
@Prince: More relevant now, thanks! –  Adam Lindberg Sep 7 '11 at 9:55
add comment

3 Answers

up vote 5 down vote accepted

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>
share|improve this answer
1  
+1 : Nice idea to remap ci( ! –  Xavier T. Sep 7 '11 at 9:52
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. –  Adam Lindberg Sep 7 '11 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 Sep 7 '11 at 10:18
    
@Prince: Unfortunately. :-( –  Adam Lindberg Sep 7 '11 at 10:37
    
I'll mark this as accepted since it has a partial solution that might work for someone. +1 for learning f(. –  Adam Lindberg Sep 8 '11 at 7:25
show 1 more comment

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.

share|improve this answer
2  
Although a useful property would to be, if no outer scope is found, the next on the line could be chosen? –  Adam Lindberg Sep 7 '11 at 10:17
add comment

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)

share|improve this answer
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 Sep 7 '11 at 9:53
add comment

Your Answer

 
discard

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.