News for hackers. Stuff that matters.
Re:Vim 8.0 is coming by zwarag on Wednesday April 13, 2016 @05:55AM (#11486915)
I make a list for things I know would be faster if I knew them and go on.

example of my vimimprove.md:

- 5 deleting word while curser is in the middle of that word

- 2 insert parantesis around the word im on

....

when something reaches 10, I google it and write it on a note. Then the first thing I do in the morning is doing that thing 10 times. Before I leave work, I do it again. And of coarse if you use it while working you might just have it in your muscles or you look at your little note. Then after a while your finger get that ninja stile of doing stuff you brain just things about.

Like ying and yang

Re:Vim 8.0 is coming by arnsholt on Wednesday April 13, 2016 @06:05AM (#11486954)
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).

Re:Vim 8.0 is coming by aidos on Wednesday April 13, 2016 @06:13AM (#11486985)
If 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.

Re:Vim 8.0 is coming by thomasahle on Wednesday April 13, 2016 @06:27AM (#11487034)
Nice use of the buffer. Is there a nice hack to remove the parentheses around a word as well?
Re:Vim 8.0 is coming by aidos on Wednesday April 13, 2016 @06:36AM (#11487064)
I guess you could do a similar thing: ci(<backspace><delete><esc>p
Re:Vim 8.0 is coming by ksmithbaylor on Wednesday April 13, 2016 @07:53AM (#11487369)
ca( would work for this as well.
Re:Vim 8.0 is coming by saltycraig on Wednesday April 13, 2016 @09:04AM (#11487758)
If 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.
Re:Vim 8.0 is coming by mkehrt on Wednesday April 13, 2016 @03:08PM (#11491229)
Take a look at vim-surround, which adds mappings for a lot of things like this.
Re:Vim 8.0 is coming by sillysaurus3 on Wednesday April 13, 2016 @06:18AM (#11487003)
Handy trick. Thanks!
Re:Vim 8.0 is coming by sevensor on Wednesday April 13, 2016 @09:35AM (#11487991)
What'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?
Re:Vim 8.0 is coming by widdma on Wednesday April 13, 2016 @10:10AM (#11488273)
The '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.
Re:Vim 8.0 is coming by sevensor on Wednesday April 13, 2016 @10:39AM (#11488548)
Interesting. 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.
Re:Vim 8.0 is coming by sooheon on Wednesday April 13, 2016 @12:33PM (#11489702)
Try 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.
Re:Vim 8.0 is coming by sevensor on Wednesday April 13, 2016 @04:10PM (#11491767)
It 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.
Re:Vim 8.0 is coming by bgribble on Wednesday April 13, 2016 @07:55AM (#11487376)
vim-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>

Re:Vim 8.0 is coming by grayrest on Wednesday April 13, 2016 @01:43PM (#11490395)
> deleting word while curser is in the middle of that word

:help text-objects

Text Objects are really the best thing about vim after the command grammar itself.

> insert parantesis around the word im on

Install surround.vim and add the following to your .vimrc (I think s duplicates c too closely for the prime keyboard position. Therefore, s is for surround):

    nmap s      ysi
    nmap S      ysa
    nmap s$     ys$
    nmap sv     gvs
You can then surround whatever text object you want. Surround the current word with `sw(`, surround the current braces with `s{(`, etc. The `sv` prefix lets you surround the thing you just surrounded: `sw"sv(` turns `wo|rd` -> `("wo|rd")`.