I can’t find a solution (here and on the web) for simply selecting/inserting/deleting stuff surrounded by dots (a common case in development) :
someobject.some-property-with-hyphens.otherproperty
How to select the middle property ?
I tried :
vi. (dot is for executing last command)
viw (don't include hyphens)
4viw (still nop)
vis (select full line)
Edit : more common exemple (in javascript)
app.object['key'].$object_with_a_dollar_sign.function()
I suspect the real issue here is that hyphens are not considered a part of an identifier
You should try adding
for your file type. That way, viw will do exeactly what you want
To make this setting automatic for, say,
strangefiles:Adding that line to your vimrc (
:e $MYVIMRC) you’ll never have to think about adding the iskeyword setting. See also:he modelinefor alternative ways to set this setting per fileUpdate an even purer solution would to create your own operator-mapping.
A quick draft of this, that seemed to work very nicely for me:
Examples for the following buffer contents (cursor on the letter
w):some-property-with-hyphens.in visual mode.some-property-with-hyphens.in visual modesome-property-with-hyphensin visual modeMotions can be chained and accept a
count:some-property-with-hyphens.SUB.in visual modesome-property-with-hyphens.SUB.in visual mode.some-property-with-hyphens.SUB.in visual modesome-property-with-hyphens.SUBin visual modeYou can use the operators as operators to any editing command:
someobject.SUB.otherpropertysomeobject.shortname.SUB.otherpropertysomeobject.get("otherpropertyIt doesn’t matter where in a ‘dot-delimited-identifier’ the cursor is to start with. Note that for convenience, all visual mode mappings position the cursor at the end of the selection (so you can do continue extending the selection by e.g.
%and other motions).