How do you delete all text above a 开发者_运维百科certain line. For deletion below a line I use "d shift g"
dgg
will delete everything from your current line to the top of the file.
d
is the deletion command, and gg
is a movement command that says go to the top of the file, so when used together, it means delete from my current position to the top of the file.
Also
dG
will delete all lines at or below the current one
:1,.d
deletes lines 1 to current.
:1,.-1d
deletes lines 1 to above current.
(Personally I'd use dgg
or kdgg
like the other answers, but TMTOWTDI.)
kdgg
delete all lines above the current one.
Providing you know these vim commands:
1G -> go to first line in file
G -> go to last line in file
then, the following make more sense, are more unitary and easier to remember IMHO:
d1G -> delete starting from the line you are on, to the first line of file
dG -> delete starting from the line you are on, to the last line of file
Cheers.
d1G
= delete to top including current line (vi)
:.,$-3d
deletes from current line to 3 lines from end
精彩评论