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

Same with the "i" (inner) command.

(Technically it's a motion, not a command. "i" as a command just enters insert mode.)

To elaborate, since this is one of my favourite vim features, say you have the following code:

    do_something_with(some + long * complicated * expression)
                               ^
Say your cursor is where the caret indicates. Typing 'ci)' ("change inside parens") in normal mode will:

* delete all the text between the two matching parens

* place you in insert mode with the cursor between the two (now adjacent) parens

* put the deleted text in the yank buffer so that 'p' will paste it.

The use case here is obviously so you can assign a name to that long complicated expression. 'ci)' is much easier than selecting it with the mouse, and keeps your hands on the keyboard where they belong ;)

With nested parentheses, it does what you expect (affects the text contained by the innermost matching pair to contain your cursor - try it and see).

Other equally useful variants:

* i" - "inside double quotes" - everything between double quotes

* i' - "inside single quotes"

* iw - "inside word" - the word the cursor is on

* is - "inside sentence" - great for editing prose

* ip - "inside paragraph"

There are also similar motions beginning with "a":

* a) - like i) but includes the parens (e.g. 'da)' deletes everything inside parens and the parens themselves)

* a" - similarly

* aw - like iw but includes trailing whitespace.

(Update - I thought this deserved its own air, so I turned it into a blog post: http://blog.samstokes.co.uk/post/767636740/vim-wizardry-1 Bonus tip if you read to the end!)




And if you like operating inside of matching pairs, just think how much you'll like manipulating the pairs themselves! http://github.com/tpope/vim-surround


This is really interesting. I don't vim much anymore but thanks for this!


WOW.

I've been using Vim for over a year and had no idea about this.

Holy crap, that's awesome.

My only regret is that I have but one upvote to give!

I always used to do F(lvf)hc rather than ci)


Heh, this is now my most popular HN comment to date. Thanks for the upvotes!




Applications are open for YC Summer 2019

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

Search: