3
votes
2answers
115 views

How to format a string substitute, or a text line, in Vim?

Is it possible to format the replacement string when substituting a match with Vim? Say I have a file with a 2-column table, where the entries in each row are separated with a space. The entries (and ...
0
votes
1answer
49 views

Handling punctuation in text pattern with vim search/replace

In vim we have the :substitute command that searches for a text pattern and replaces it with a text string. How does one handle a text pattern with punctuation in it? Minimum working example: the ...
1
vote
3answers
42 views

How to Copy words highlighted after search directly into command line with shortcut?

Here is the situation, for example, I have several lines like this: foo test foo I searched "foo" with "/" and all the two "foo"s above are highlighted. And now I want to replace "foo" with ...
1
vote
1answer
62 views

Need help formulating a Vim Search & Replace

I have a large html file in which I need to search and replace over 2000 occurrences of specific string. I could do it manually but I'm sure there is a power Vim search and replace command that could ...
3
votes
2answers
1k views

Multiple search and replace actions in one large text file

I have a big text file (about 2GB). I want to do five search and replace actions on the same file, and would like to do this in one command. Normally I use vim, open the file, do one replace action, ...
1
vote
1answer
240 views

Replace a regular expression within vim with an output produced by a console command with the expression as its argument?

let's say I have a file with the following content: This is a _file_ which has some _special_ keywords, that I would _like_ to replace. I can do a search and replace of the speical keywords ...
1
vote
4answers
144 views

Search and Replace string in Vim

I have code similar to this: $POST_['%'] where % is any length any letter+numbers string and I want to replace it with mysql_real_escape_string($POST['%']) so far I have built up this command ...
0
votes
2answers
618 views

Remove lines not containing a word in Vim

In Vim I often find I'm only interested in lines containing a certain string of text and want to delete all other lines. It's easy to match lines containing a string: :s/^.*foo.*\n// What I ...
3
votes
2answers
34 views

How to insert a recent search pattern to use for search-and-replace in vim?

I've entered some search pattern in vim using / command. Now, I want to replace those occurrences I've found with something else. How do I easily insert the recently used search pattern into the :%s/ ...
2
votes
3answers
99 views

using vims pattern-multi-items {n} to match the 5th space in a line

With this entry from our crontab 1 3 1 * * find /var/log/tomcat/* -mtime +61 -type f -delete I want to match the 5th space char so I can separate the command part from the time field part. Cron ...
5
votes
2answers
2k views

how to do a vim search inverse search for all lines with out text

with grep I can do a grep -v "my search" to get all the lines with out "my search" with sed I can sed '/baz/!s/foo/bar/g' to find replace text on lines with out baz Is there a way to do the same ...
10
votes
1answer
3k views

vim delete all lines that do NOT contain a certain word

In vim I can delete all lines that contain the word "price" with this :g /price/d How can I delete all lines that do NOT contain the word "price"?
3
votes
1answer
349 views

Can I delete any line with a given search string?

In Vim, I'd like to search for lines with a given string, then delete them. Specifically, I'd like to find lines with the LaTeX commands \begin{frame} and \end{frame}, and delete them. =
1
vote
2answers
393 views

Change YYYY-MM-DD to YYYYMMDD everywhere in file

I can't just delete all of the hyphens, because elsewhere they are used as minus signs. I can find these dates with [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} but I can't figure out how to keep those three ...
1
vote
1answer
343 views

Add constant value to numeric XML attribute

Background Add a constant value to numbers matched with a regular expression, using vim (gvim). Problem The following regular expression will match width="32": /width="\([0-9]\{2\}\)" Question ...
22
votes
7answers
14k views

How to remove this symbol “^@” with vim?

I have some files that are corrupted with this symbol: ^@ It's not part of the string; it's not searchable. How do I substitute this symbol with nothing, or how do I delete this symbol? Here ...