1

This is arguably a micro-optimisation but given the following:

<div class="ClassOne ClassTwo">Content</div>

Using Vim, and with my cursor anywhere on that line, I wondered if there is a way to change the 2nd word in the quotes using the change action? I realise I can jump there and remove the word in a number of ways (fTcaw as one example) but wondered if there is a way using Change within a context (rather than just finding and changing that particular word)?

I tried c2wi" and cw2i" but no joy. Is there a way using 'change in' or does that always delete all content inside?

Ben Frain
  • 2,510
  • 1
  • 29
  • 44
  • The text object is inner quotes. I don't think you can combine text object with motions (which is what it seems like you are trying to do). If you wanted you could write a custom text object. – FDinoff Aug 22 '14 at 01:53
  • OK, that was my suspicion. I'll have a look at writing a custom text object. – Ben Frain Aug 22 '14 at 10:00

2 Answers2

1

Example-Specific Solution:

$Bcw

More Generalized Solution:

  • ^ - reorient cursor from 'anywhere on that line' to the beginning
  • f" - go to first quote, use ; if needed to jump down a line with multiple quote blocks
  • W - move to beginning of next WORD (one less key than 2w)
  • cw - change word

Variations:

  • for the first word, use w instead of W
  • for the third~nth word, use w multiple times or prefix it with a number, e.g. 3w
  • iterate backwards from the end of the quotes: $F"b
Community
  • 1
  • 1
Kache
  • 15,647
  • 12
  • 51
  • 79
0

How about creating a simple macro?

qa + do marko of your choice 0f"wwcw + exit makro q

Call makro @a on any line.

zzart
  • 11,207
  • 5
  • 52
  • 47
  • 1
    Yes, that's a possibility but it's not an 'expressive' way to do it. For example, what if I want to change the 3rd word in quotes or 1st word in quotes. Was just wondering if there's a way to do it with Vim's core language. – Ben Frain Aug 21 '14 at 23:14