diff --git a/README.md b/README.md index ff792b3..98deb1c 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Count the Number of Matches](vim/count-the-number-of-matches.md) - [Create A New Directory In netrw](vim/create-a-new-directory-in-netrw.md) - [Create A New File In A New Directory](vim/create-a-new-file-in-a-new-directory.md) +- [Delete Every Other Line](vim/delete-every-other-line.md) - [Delete Lines That Match A Pattern](vim/delete-lines-that-match-a-pattern.md) - [Deleting Directories Of Files From netrw](vim/deleting-directories-of-files-from-netrw.md) - [Edges Of The Selection](vim/edges-of-the-selection.md) diff --git a/vim/delete-every-other-line.md b/vim/delete-every-other-line.md new file mode 100644 index 0000000..66f830e --- /dev/null +++ b/vim/delete-every-other-line.md @@ -0,0 +1,21 @@ +# Delete Every Other Line + +You can delete every other line in the current buffer using the following +command. + +There is a fairly elegant way in vim to delete every other line in the +current buffer. Why would you want to do that? I don't know. Nevertheless, +here it is: + +``` +:g/^/+d +``` + +This will essentially delete all even numbered lines. If you'd like to +delete all odd numbered lines, delete the first line in the file (`ggdd`) +and then run the same command as above. + +This syntax is a bit awkward, so you may be better off going straight for a +macro (e.g. `qqjddq5@q` or `qqddjq5@q`). + +[source](http://stackoverflow.com/questions/1946738/vim-how-to-delete-every-second-row)