4 ms·
Since I happen to have the answer to both of those: `daw` and `diw` deletes a whole word (unlike `dw` which only deletes forward). They differ in what they do
by arnsholt 11y ago
Since I happen to have the answer to both of those:
`daw` and `diw` deletes a whole word (unlike `dw` which only deletes forward). They differ in what they do with whitespace; `aw` also trims trailing whitespace (or leading whitespace if there's no trailing) while `iw` leaves the whitespace alone. These two are text objects that can be combined with other commands and quantifiers, so that `yaw` copies a word without deleting it, or `d2aw` deletes two words.
Wrapping in parens requires the vim-surround plugin, but with that installed you can do `ysaw(` and `ysaw)` to wrap in parens (also works with brackets and curlies and such), either with spaces inside the parens (the former) or snugly around the word (the latter).
- aidos 11y agoIf I want to put parens around a word I do, ciw()<ESC>P (change word pulls it into the default register, insert the parens and then paste from the register back between the parens). You can use the same pattern for any selection you have visually highlighted, such is the wonderful power of vim.
- sillysaurus3 11y agoHandy trick. Thanks!
- thomasahle 11y agoNice use of the buffer. Is there a nice hack to remove the parentheses around a word as well?
- aidos 11y agoI guess you could do a similar thing: ci(<backspace><delete><esc>p
- ksmithbaylor 11y agoca( would work for this as well.
- saltycraig 11y agoIf you have the cursor just before the area you could do: 'dt)' meaning delete to next ), or 'ct)' to delete until next ) and the drop into insert mode. Learning word objects in Vim for me is one of the killer features, and one thing I miss in Emacs.
- mkehrt 11y agoTake a look at vim-surround, which adds mappings for a lot of things like this.
- bgribble 11y agovim-surround is the bee's knees. `cs"'` change surrounding double quotes to single `dst` delete surrounding HTML tag pair `ysiptp>` wrap this paragraph in <p></p>
- sevensor 11y agoWhat's the difference between bdw and daw? I already use "b", "e", and "w" quite a lot, so the "a" and "i" infixes seem a little redundant. Is there an advantage to the infixes that I'm not seeing?
- widdma 11y agoThe 'a' and 'i' in this context operate on text objects. They're much more powerful than motions. For example, beyond the 'w' for word, there is 'p' for paragraph, '"' for double quotes. All of these allow you to edit the object while the cursor is inside them.
- sevensor 11y agoInteresting. I'd have to use ?" and /" for double quotes, although I do have () and {} for sentences and paragraphs. I'll have to go back to the documentation -- I suppose there's a "whatever is within the current pair of parentheses" text object? I could see using that quite a lot.
- sooheon 11y agoTry doing `cas` (change a sentence) or `dib` (delete in brackets), and on and on for all your different text objects. This infix notations are not redundant, because they are not motions like `b` `e` `w` are, but adjectives to be applied to the nouns which are text objects.
- sevensor 11y agoIt looks like I need to learn what the text objects are. I learned vi about 20 years ago, and I've been using vim like vi ever since.