I know in VIM how to search a string and delete the text till the start/end of line but I would like to know if it is also possible to delete all text in line before or after highlighted search pattern.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to do this across all lines and don’t want to retype your search term I’d suggest the following:
What this does is:
%s/: substitute across all lines in a file.*: match any character\ze: end matching so the rest of the pattern is not substituted<Ctrl-r>/: insert text from the ‘/’ register (which is the search register)//: replace with nothingEdit: Forgot about the after part. My suggestion to remove both at the same time would be: