Vi Command - find a line but delete 2 lines above it.?
-
In Unix vi what is the command to find a line then delete a line that is 2 lines above it. For example I have a file that I have opened in vi. There are lots of occurences where something like this will happen: Config 1 Config 2 Config 3 the one I want That pattern repeats a lot through out the file. I want to fine the line that says "the one I want" but delete 2 lines above it (i.e. delete the line that says "Config 2"). Unforunately I can't just do a search and delete of a line that says "Config 2" because that occurs in other places that I want to keep it in.
-
Answer:
jump to 'the one I want' 2k,dd and remember that recording macros in vim is dead easy. would be useful here.
razzacom at Yahoo! Answers Visit the source
Other answers
Like she said above. :1 <enter> (goto beginning of file) q r (begin recording macro named 'r', name must be one character) ('r' as in repeat or whatever you want) :/the one I want <enter> (search the one you want) 2kdd2j (2k: move cursor 2 lines above, dd: delete a line, 2j: move cursor 2lines below (below the one you want)) q (stop recording macro) @r (run macro named 'r' once) 100@r (run macro 'r' 100 times) Make sure not to run macro too much, otherwise it will start to delete other lines near the end of file. Gotta love Unix. Is there anything like this in Windows? Powershell maybe?
Related Q & A:
- How to do a line break for a UITextField?Best solution by Stack Overflow
- How to delete a line from a .txt file in node.js?Best solution by c-sharpcorner.com
- How to paste a line at a time?Best solution by Ask Ubuntu
- Where can I find a cruise line job?Best solution by Yahoo! Answers
- Where can I find a small end 4 pin fire wire and a 5 pin mini usb 2.0 cable that connects a external harddrive?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.