问题
I have a line like this in a file
<echo>The app vendor is... app.server.name</echo>
With the cursor over the 'r' in 'server', how can I yank 'app.server.name' without going into visual mode, or without having to guess the number of words to yank.
yiw will only yank the word inbetween the periods.
回答1:
Byt<
B (to get you to the beginning of the punctuated word)
yt< (to yank forward, up to but excluding the "<").
回答2:
1. Quick and dirty: include dots in 'word' matching
:se iskeyword+=46
Now yiw will do what you want :)
2. Proper solution: define a text object
As Benoit mentions, the above might be side effects that you don't want1
In an earlier answer ( vim: select inside dots) I describe how to definte a text object to select inside dots (shown below). You could use that as a basis to define a similar text object that selects words including dots:
This doesn't require any changes to the iskeyword setting :)
xnoremap <silent>. f.oT.o xnoremap <silent>a. f.oF.o xnoremap <silent>i. t.oT.o onoremap <silent>. :<C-u>exec 'normal v' . v:count1 . '.'<CR> onoremap <silent>a. :<C-u>exec 'normal v' . v:count1 . 'a.'<CR> onoremap <silent>i. :<C-u>exec 'normal v' . v:count1 . 'i.'<CR>Examples for the following buffer contents (cursor on the letter
w):someobject.some-property-with-hyphens.SUB.otherproperty
- v. selects
some-property-with-hyphens.in visual mode- va. selects
.some-property-with-hyphens.in visual mode- vi. selects
some-property-with-hyphensin visual modeMotions can be chained and accept a
count:
- v.. selects
some-property-with-hyphens.SUB.in visual mode- v2. also selects
some-property-with-hyphens.SUB.in visual mode- v2a. selects
.some-property-with-hyphens.SUB.in visual mode- v2i. selects
some-property-with-hyphens.SUBin visual modeYou can use the operators as operators to any editing command:
- d. results in
someobject.SUB.otherproperty- ci.shortname results in
someobject.shortname.SUB.otherproperty- c2.get(" results in
someobject.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).
1 see a bit of background information here: vim: select inside dots
来源:https://stackoverflow.com/questions/7914019/yank-words-separated-only-by-periods