LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   vi question regarding removing part of a line (http://www.linuxquestions.org/questions/linux-newbie-8/vi-question-regarding-removing-part-of-a-line-541954/)

RobHill 03-30-2007 12:31 PM

vi question regarding removing part of a line
 
What command can I use to delete everything from the beginning of a line up to a specific word in the line? Let me add to that, I want to do it for an entire file, not just a fe lines in the file. :)

MensaWater 03-30-2007 12:35 PM

If you knew how many "words" there were you could do #dw where # is the number of words before what you want to delete.

e.g.
"The quick brown fox jumped over the lazy dog"

From start of line 5dw would leave you with:
"over the lazy dog"

It gets tricky sometimes figuring out what a "word" is. Usually it is items separated by white space however some characters are treated as words.

e.g.
The quick brown (fox) jumped over the lazy dog

From start of line 5dw would leave you with:
") jumped over the lazy dog"
because it counted the "(" as a "word".

jlliagre 03-30-2007 02:42 PM

Try that one, assuming the word is "foo" and you want to keep it:
Code:

:% s/^.*\<foo\>/foo/


All times are GMT -5. The time now is 10:42 PM.