Re: quick question
- Chris Hudson schrieb:
>How would I replace every line in a file that starts with certain text, forif e.g your file lookss as follows
>example every line that begins with 22.
LINESTART this is the rest of the first line
LINESTART this is the rest of another line
-replace every line starting with "LINESTART" with the text
"replacement" and prompt for
means "work on all lines of the file"
means "search and replace globally (g) with confirmation (c)"
means "match every occurence of string LINESTART at the beginning of a
means "followed by any character (.) 0 or any times (*)"
- On Thursday 01 December 2005 17:30, Chris Allen wrote:
> On 01/12/05, Chris Hudson <chudson@...> wrote:Hi Chris and others,
> > How would I replace every line in a file that starts with certain text,
> > for example every line that begins with 22.
> The 'substitute' command. For example:
> %s/^22.*$/my replacement text/
> That would replace anywhere in the whole file (%) a string which
> started (^) with 22 (22) and then continued on with anything (or even
> nothing) (.*) to the end of the line ($). See also :help :s
> You can also delete any line starting with a certain string using the
> :global command, if you decide you'd rather do that. Something like:
> :g/^22/ d
> Chris Allen
This is one of the first decent answers I've seen on this list. I've been
using (g)Vim now for a number of years sporadically. Recently I've changed
jobs and I now have a development job in embedded linux, so I am using Vim
more often now. The last few months I've made a concerted effort to improve
my Vim skills. Using the Vim Regular expressions is obviously one of the
powerful tools in the search/replace functions. They are explained in the
This response is however a good example of how one can learn via example. Most
of the answers on questions on this list is simply a post of the commandline
and it is assumed that the person asking the question knows what the symbols
mean in the search replace. Your response does however show exactly what each
expression does and makes it easier for the reader helped by your response to
achieve fluency in regular expressions faster.