Selecting text inside parenthesis from outside the parenthesis in Vim

前端 未结 2 1009
傲寒
傲寒 2020-12-06 05:36

I know that I can select text inside quotes/doublequotes by issuing vi\' or vi\". For example, with cursor at H, I can select Wo

相关标签:
2条回答
  • 2020-12-06 06:00

    The difference between {a,i}×{(,),b} text-object commands and their ", ', ` counterparts primarily results from the different definitions of a block and a quoted string (see :help v_ab, :help v_aquote).

    While the latter is the text from the previous quote character on the current line until the next one on that same line (escaped ones aside), the former is the text between the nth previous unmatched opening parenthesis and the matching closing one. Simply put, the command va( (without a count) is like [(v%—if there is no unmatched parenthesis before the cursor, both select nothing. However, the command va" scans the current line to find a matching pair of quotes anyway.

    The main reason for this difference in behavior, I suppose, is that quoted strings, in contrast to parenthesis, are assumed to be non-nested (at least in perspective of the built-in Vim text objects).

    To select the text in the next parenthesis on the current line, one can use

    %vi(
    

    or, to include parenthesis into selection,

    %va(
    
    0 讨论(0)
  • 2020-12-06 06:01

    This comment on Hacker News points to a script supposedly solving the issue.

    Untested but it's by Steve Losh so it might be good.

    0 讨论(0)
提交回复
热议问题