3 ms·
question about text objects: given the following string and with the cursor over f: function(1,2,"3") why does di" yield: function(1,2,"") but di
by dschobel 15y ago
question about text objects:
given the following string and with the cursor over f:
function(1,2,"3")
why does di" yield:
function(1,2,"")
but di( has no effect unless you are within the parenthesis already?
Why doesn't di( when issued over the f in function yield the following?
function()
- deleted 15y ago[deleted]
- cdavoren 15y agoIt looks like the 'i(' motion has special meaning in Vim - it corresponds to the previous unmatched '(' to the next matched ')'. Type 'help motion.txt' and look for i(. Edit: Actually, the description for i" implies that its behaviour should be the same. Which one works correctly, I wonder?
- thristian 15y agoSince brackets come in matchable pairs and double quotes do not, and because brackets can be nested while double quotes cannot, it wouldn't surprise me if this were a deliberate difference. If the user hits "di(" on a line and there's no "(" before the cursor, you can search backwards over previous lines looking for an unmatched "(" without too much worry you'll get confused by a stray "(" and delete something the user didn't expect. If the user hits 'di"' on a line and there's no '"' before the cursor, searching any further is quite likely to hit a false positive and do something ridiculous (like deleting all the code between two string literals).
- cdavoren 15y agoThat's a fair interpretation. I'd be more comfortable if this difference were reflected in the documentation - it could at least state that if no previous quote is found, the next quote on the line will be used.