Hacker News new | past | comments | ask | show | jobs | submit login

For the eight years I've been using vim, I have never known about ci". I feel both stupid and in awe.



'i' and 'a' (mnemonic: the 'a' grabs all of something (and its white space) as opposed to 'i' which grabs the inner part) as modifiers for 'c', 'd', 'y', and 'v' can be very useful, but I don't see them talked about much in most tutorials.

See :help motion.txt - they're in section 6. Text Object Selection. Also, just play around with them a little. For example:

   <p>This is a tes|t. Do not be alarmed.</p>
If that's your text, and the cursor is at the pipe:

    ciw  # remove all of 'test', enter insert mode
    caw  # remove the word 'test' and preceding space, enter insert mode
    vit  # visually select all the text within the <p> tags
    vat  # visually select the whole <p> element


and diw and daw delete the whole word, gUiw uppercases the whole word, and ...

The composability of vim motion commands is what keeps me using it.


Hmm for some reason my motions don't work with [ { ( or b/B. I can't seem to find a reason for this. " works though.

Edit: seems actual jump selection can be finicky.


Check out this: http://blog.interlinked.org/tutorials/vim_tutorial.html (text-objects section in particular).


You can use other characters too: like ', {, [, (, t (HTML tag).

Even better, you can use b instead of ( and B instead of {, because it's easier to type.


same here, though i quite religiously use df" and d%.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: