I have some text like this:
foo<space><space><space>'bar'
When I do da'
inside 'bar'
, the whitespace is removed:
foo
How can I do da'
without removing whitespace, so I get this as the result?
foo<space><space><space>
I found this in vim's help topic on text-objects
:
i" *v_iquote* *iquote*
i' *v_i'* *i'*
i` *v_i`* *i`*
Like a", a' and a`, but exclude the quotes and
repeating won't extend the Visual selection.
Special case: With a count of 2 the quotes are
included, but no extra white space as with a"/a'/a`.
Thus, doing the below would not delete the whitespace.
d2i'
For more help on text objects, do :help text-objects
This is covered in :help v_i'
:
For the "a" commands: The operator applies to the object and the white space after the object. If there is no white space after the object or when the cursor was in the white space before the object, the white space before the object is included.
So, the problem is that you're at the end of the line. To change the behavior, you can add a whitespace, go back, and then issue the command: A<Space><Esc>hda'
.
Alternatively, use the inner object, and remove the two quotes afterwards, as in di'hxx
.
For the quote text objects, there's even a handy special case, so d2i'
looks like the winner here:
Special case: With a count of 2 the quotes are included, but no extra white space as with a"/a'/a`.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With