7

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.

glts
  • 21,808
  • 12
  • 73
  • 94
centerback
  • 619
  • 4
  • 16
  • This title is misleading, you're not actually looking to yank between "whitespace" – eugenevd Aug 01 '13 at 17:34
  • So, not only is the title misleading, but you also accepted, over 2 years later, an answer that is incompatible with either the title or the question wording. Would you please consider fixing your question? – sehe Nov 25 '13 at 14:36
  • How do you figure that sehe? I don't want to yank between white space, I want to "Yank words separated only by periods". Also I only changed the accepted answer after this question popped up in my notifications, as someone had recently tagged it as "nice question". – centerback Nov 26 '13 at 09:27

2 Answers2

20
Byt<

B (to get you to the beginning of the punctuated word)

yt< (to yank forward, up to but excluding the "<").

odrm
  • 5,149
  • 1
  • 18
  • 13
12

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-hyphens in visual mode

Motions 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.SUB in visual mode

You 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("otherproperty

It 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

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • but it can also have side-effects probably. – Benoit Oct 27 '11 at 13:38
  • @Benoit: I addressed your concerns. I also linked to [my earlier answer](http://stackoverflow.com/questions/7292052/vim-select-inside-dots/7292271#7292271) that defined an [operator-mapping](http://vimdoc.sourceforge.net/htmldoc/map.html#%3amap-operator) to define a custom _text object_ :) Hope that helps – sehe Oct 27 '11 at 13:53