How to do it in Vim:
BEFORE:
aaa
bbb
ccc
ddd
eee
fff
AFTER:
aaa
ccc
eee
How to do it in Vim:
BEFORE:
aaa
bbb
ccc
ddd
eee
fff
AFTER:
aaa
ccc
eee
You should be able to use a macro:
http://www.oreillynet.com/mac/blog/2006/07/more%5Fvim%5Fsave%5Ftime%5Fwith%5Fmacros%5F1.html
You can use a macro for this. Do the following.
gg
.qq
.dd
after.q
.10000@q
PS: To go to command mode just press Escape a couple of times.
from vim mail archive:
:let i=1 | while i <= line('$') | if (i % 2) | exe i . "delete" | endif | let i += 1 | endwhile
(To be typed on one line on the vim command line, will delete row 1,3,5,7,...)
You can always pipe though a shell command, which means you can use any scripting language you like:
:%!perl -nle 'print if $. % 2'
(or use "unless" instead of "if", depending on which lines you want)
:%!awk -- '++c\%2'
alternatively
:%!awk -- 'c++\%2'
depending on which half you want to weed out.
You can use Vim's own search and substitute capabilities like so: Put your cursor at the first line, and type in normal mode:
:.,/fff/s/\n.*\(\n.*\)/\1/g
.,/fff/
is the range for the substitution. It means "from this line to the line that matches the regex fff
(in this case, the last line).s///
is the substitute command. It looks for a regex and replaces every occurrence of it with a string. The g
at the end means to repeat the substitution as long as the regex keeps being found.\n.*\(\n.*\)
matches a newline, then a whole line (.*
matches any number of characters except for a newline), then another newline and another line. The parentheses \(
and \)
cause the expression inside them to be recorded, so we can use it later using \1
.\1
inserts the grouped newline and the line after it back, because we don't want the next line gone too - we just want the substitution mechanism to pass by it so we don't delete it in the next replacement.This way you can control the range in which you want the deletion to take place, and you don't have to use any external tool.
:map ^o ddj^o
^o
Here ^ stand for CTRL. Recursive macro to delete a line every two line. Choose well your first line and it's done.