Questions tagged [replace]

Command or mode to overwrite text. For search-and-replace operations, use the [substitute] tag.

Filter by
Sorted by
Tagged with
28
votes
5answers
1k views

How to replace a word with a yanked word in normal mode

When I have to replace a word with another word I yank before, I usually use a workflow which seems unnatural to me: Let's say I have this text: foo bar buzz And I want to yank foo and replace bar ...
10
votes
5answers
3k views

Replace selection with output of external command

Assuming I have a line in a file with XXXX being a placeholder I have selected via v as follows: XXXX Some other text How can I change only the XXXX with the output of an external command, such as ...
12
votes
3answers
11k views

Insert an incrementing number to each line in either a selection or a match

I have a problem I can think of two general approaches for solving, but I don't know specifics for either approach. ... Level 1: cũng also Level 1: và and Level 1: như like; such ...
10
votes
2answers
7k views

Multiline Search and Replace

Would like to perform a search and replace in a file with 12000 lines. Specifically, if an occurrence of ^ SetFontSize 28 exists after a ^Hide block and before the next ^Hide or ^Show, change 28 ...
12
votes
3answers
431 views

How to selectively change a hightlighted string?

By searching, I've highlighted the string that I want to change. Now I want to replace only the highlighted text. I'm using n to advance to the next instance of the search string. I was thinking I ...
9
votes
7answers
4k views

How to replace a pair of brackets

I have a file, containing some lines like this: aaa bbb (ccc) ddd. Now I want to replace the pair of brackets by a pair of square brackets to make this line become aaa bbb [ccc] ddd. I think that \...
7
votes
2answers
3k views

Replace current selection and all identical occurrences in a file

This is a sample sentence. This is a second sample sentence. Let's say I select 'is a' of the first sentence. Now I want to change all occurrences of what is selected (including the selection itself) ...
4
votes
1answer
2k views

Change/delete matching brackets at the same time

Sometimes I write something in brackets and then realize I've typed the wrong kind. For instance, in LaTeX: \command(arguments) Which should be: \command{arguments} I can jump between the two ...
14
votes
3answers
7k views

How to replace more than one character without entering insert mode

I have a file with a line that looks like this: foofoo.xy.barbar I want to change the xy to gh. I tried to do 2r -> gh, but obviously that didn't work, as it replaced the xy with gg and then moved ...
7
votes
3answers
163 views

mapping to enclose symbol under cursor with an expression that contains the symbol

Have been reading vim scripting posts for an hour, but I'm afraid I don't have the skills to apply these posts to my problem. Editing math in latex documents, I'm frequently wanting to replace math ...
3
votes
4answers
366 views

How to run a python command based on a matched group of a pattern?

Let say I want to run a command that uses a matched group of a pattern for each line matching the pattern. The natural choice is :g. With the command :s, there is no problem. If i would do :g/aaa\(....
3
votes
2answers
1k views

Using global command on Quickfix entries [duplicate]

I find and replace a pattern in all the files in my project (which is a big one). After the search is done, quickfix window is opened with the matches. The matches are in different files in different ...
2
votes
4answers
976 views

Search for line, move to end of search string, then search+replace

(EDIT: In the original question, I had accidentally used \w instead of \<. Comments and answers with \w should be interpreted as using \< as well.) In my LaTeX source files, section headings ...
1
vote
1answer
1k views

How to paste a text block in visual block mode?

I want to paste text which spans across multiple lines and is rectangular. For example, a rectangular box representing a device topology diagram. +-------+ | | | | ...
1
vote
1answer
117 views

Replace a character multiple times but within pattern

I am creating a yml file out of some variables. I have like 80 lines and they all have the pattern: my-first-command-line-var: {{ my-first-command-line-var }}, my-second-cli-var: {{ {{ my-second-cli-...