Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

Vim: Can you delete a specific line number from another line?

I was on line 93 and realized I wanted to delete line 89. I typed :d89 in hopes that line 89 wold be deleted. It didn't work.

Does anyone know a good way to accomplish this type of interaction? I am a comfortable Vim user but have not (yet) taken the leap to writing plugins...

Thanks.

question from:https://stackoverflow.com/questions/8495094/vim-can-you-delete-a-specific-line-number-from-another-line

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The address of a colon-command (eg: the line number) comes first.

:89d

Note that this will also cause you to navigate to the location of the change. You can use `` to jump back.

If you'd prefer to have this be a single command you can define a custom command. eg:

command! -range -nargs=0 Delete <line1>,<line2>d|norm ``

This defines a command called Delete that deletes the addressed range (<line1>,<line2>d) and then navigates back (norm ``).

You can call it like:

:89Delete

You can actually invoke it with any unique prefix, so you may be able to get it down to:

:89D

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...