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

I've always thought that doing 5dd and such was a bad demonstration of Vi(m) since I never know how many lines to delete. I'll just dd multiple times. More powerful vim commands are like daw (delete all of a paragraph), di) (delete inside of a set of parentheses), and dtX (delete until the character X).



daw deletes the word you are in (delete a word). But dap deletes a paragraph. And you can tell vi what you mean by "word" and "paragraph" (I think) in your settings file.


Good catch, I meant dap.


If you use relative line numbers, 5dd makes total sense.


I tried this for a while but it never clicked for me. I prefer using semantically-meaningful groupings like paragraphs or parentheses, it just seems nicer. And relative line numbers wouldn't make, say, 5dw any easier to count.


You can use: df<char> to delete forward (including char), dt<char> to delete forward until char. (excluding char) d/<search><Enter> to delete until search pattern is found

In case you wish to type immediately after deleting, replace 'd' with 'c' in the above.


Also to add to this, dt/pattern_string_here is really handy for deleting until the occurrence of some pattern.


My shorthand when I don’t know the number of lines is dj followed by a bunch of .’s :)


I prefer Vim's visual mode (Shift+V) for that.

But yes, `dap` and friends are options too.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: