开发者

How do you delete all text above a certain line

开发者 https://www.devze.com 2023-01-24 12:17 出处:网络
How do you delete all text above a 开发者_运维百科certain line. For deletion below a line I use \"d shift g\"dgg

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

0

精彩评论

暂无评论...
验证码 换一张
取 消