2022 Developer Survey is open! Take survey.

Questions tagged [replace]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
25 views

How can I remove duplicates in comma-separated text, ignoring the first column, keeping only unique lines?

I have a sparse CSV file with data shaped like in this simplified example. I am omitting the header, Age,Fruit,Color,Count, but I can include it in my file if needed. You can see that the sparse rows ...
user avatar
0 votes
1 answer
26 views

Replacing regex with italic code in Vim for Latex

I am using vim to write a document in Latex. I have to replace a regex with the italic code, which is \textit{regex}. I use the Vim code: :%s/regex/\textit\{regex\}/g But the \t expression is ...
user avatar
0 votes
0 answers
16 views

Adding new line characters after a specific amount of bytes

I'd like to add new line characters after every specific number of bytes in binary mode. I tried this script but the repetition count depends on the number of characters not bytes. Like when there is ...
user avatar
  • 101
0 votes
1 answer
87 views

VIM search and replace regex - how to keep the search string intact and adding to it?

I'd like to learn how to search and replace in VIM - keeping the search string intact and adding to it. Take this as a simple example. See image below. I copied a simple python script written for ...
user avatar
3 votes
3 answers
618 views

Find and replace with incrementing numbers

I have several lines that look like the following: "Timestamp": 200, "Timestamp": 1200, "Timestamp": 3100, I want to replace all the numbers, starting at 10 and ...
user avatar
  • 31
1 vote
1 answer
25 views

How to only join lines that start with multiple spaces

what is the global command that will join lines that start with more than one space? I have tried this but it does not work as expected: :g/ \{2,}//J Example: I want to turn this: 01:001:001 In the ...
user avatar
  • 31
3 votes
2 answers
430 views

How do I replace single whitespaces without affecting multi-whitespace such as indentation in Vim?

I have textfiles with paths that have lost underscores between words inline in an OCR process. I want to keep the indentation and put back the underscores in the paths. I have a path like this: /...
user avatar
0 votes
1 answer
50 views

Key mapping for converting `((` to `\left( | \right)`

I would like to have something in .vimrc where when I type (( in insert mode, it automatically converts that into \left( | \right) with the cursor position at | in insert mode. Any ideas? I also would ...
user avatar
  • 379
1 vote
2 answers
232 views

Delete a line if it contains N occurrences

Is there a way to do a search and replace where it searches for if a line contains 4 pipes ( | ) anywhere in the line it will delete it? I'm working with a big csv file and some lines have 4 pipes and ...
user avatar
3 votes
2 answers
84 views

Is it possible to properly repeat a visual replacement?

It is possible in vanilla vim to: visual select some number of characters, e.g. a variable name in code type c to begin replacing selection in insert mode type a replacement (variable name) exit ...
user avatar
  • 2,081
0 votes
1 answer
83 views

How to replace selected text T with some function(T), using a keyboard shortcut?

I want to annotate words /sentences for a "named entity recognition" purpose; inside a text file, I want to annotating words or sentences with this format [pattern](label): [a word where the ...
user avatar
4 votes
1 answer
153 views

Search and Replace on odd/even numbered lines using g

I was looking for ways to search and replace on even/odd numbered lines in vim and I came across some solution on google groups https://groups.google.com/g/comp.editors/c/xk9DMoszgq4. To search and ...
user avatar
0 votes
1 answer
42 views

Can't find spaces in text with \s

I want to delete all the spaces in a document so I tried this: :s/\s//g but it did not work. What am I doing wrong?
user avatar
  • 1,825
2 votes
3 answers
121 views

Remove square brackets surrounding expression

In Python, I am trying to update my code from typed dict to dataclass. Language is just indicated as a reference, it is a pure Vim question. I need to replace my_params["some_property"] ...
user avatar
1 vote
1 answer
105 views

Replace two forward slashes with one using escape? [duplicate]

I am new to VI. How do you replace two forward slashes with one globally? I did: :%s/\// and :%/\//\/g Those don't work as desired. Example or Goal //This is good//because it//works; //on every//...
user avatar
  • 13
0 votes
1 answer
39 views

Replacement of characters gives ^@ when replaced with newline but not newline [duplicate]

Why does replacement of something by using :%s/,/\n/gc in vim gives me ^@ instead of giving me newline. Sed replacement works perfectly sed s/,/'\n'/g. Any idea how to do sed thingy in Vim and save ...
user avatar
  • 103
0 votes
1 answer
45 views

Cycle through a list of letters in multiple groups - Code review

This is a follow up question to Cycle through a list of letters in multiple groups where I asked how to cycle a group of letters. I got a bunch of great tips and this is my follow up question. This is ...
user avatar
0 votes
2 answers
45 views

Cycle through a list of letters in multiple groups

So I have a case where I have some unicode letters say [B, Ḅ, Ḃ] and when I have my mouse selected over the B, (in normal mode) I want some way of cycling through the list. Like pressing some command ...
user avatar
0 votes
0 answers
28 views

Insert newline (\n) at search and replace but get "^@" instead [duplicate]

I want to set a linebreak after all braces }. I tried to replace the braces by newline \n with: :%s/\}/\n/ But all I got is a ^@ instead of a new line. Example: abc{def} foo bar{baz} and so on I ...
user avatar
  • 145
1 vote
1 answer
27 views

replace simple pattern with sequential next line from another file

My file working.txt has 1000's of lines, which repeat in a simple pattern as follows: name date_ax name date_cd name date_ed name date_dc ...etc I need to replace each instance of name with the ...
user avatar
  • 531
1 vote
1 answer
63 views

Replace escape sequence `^[` carat left square bracket

Have text file with contents like: ^[[31morigin/some-branch^[[m ^[[31morigin/some-other-branch^[[m These ^[ sequences are highlighted and treated as one character as they are ascii escape sequence. ...
user avatar
  • 123
0 votes
3 answers
335 views

search and replace in whole directory recursively

I have many entities in my java project like this: public class MyCar { // The brand of the car private String brand; // The time owner bought it private Date obtainTime; // The price in dollar ...
user avatar
0 votes
1 answer
108 views

Increment number for every 10 lines

The file consists of 2 columns (code and percentage). We need to add 2 more columns with increasing number for 4th column (Xcols) and increment 3rd column (Ycols) only for every 10 lines with reset of ...
user avatar
0 votes
1 answer
46 views

When searching and replacing can I store a capture group to a register?

This is similar but I am unable to draw the information I need from it: How to store all occurrences of a multiline search in a register? I have these lines ################### trim 8 ...
user avatar
  • 531
1 vote
2 answers
66 views

Replace " ... " strings of various length with strings that all end at same column but start at different columns for each row

I have the following text Plan based ................................. 32 Iron based in Compound .............................. 34 Gallium Arsnide based III-V ............ 36 ... Indium ...
user avatar
  • 531
0 votes
2 answers
33 views

How to replace a sequence of multiple words in multiple lines with a condition of another word in the same line?

I need your kind help on writing a regular expression for the following situation. Consider the following first word sequence: Criteria A xxx xxx xxx Table1 Criteria A xxx xxx xxx Table2 Criteria A ...
user avatar
0 votes
1 answer
114 views

How to change word within snake-case-variable? [duplicate]

Consider following snake-case variable name, with the cursor somewhere within the word that we'd like to change. roses_are_red_violets_are_blue ^ # the cursor position ...
user avatar
  • 135
0 votes
1 answer
701 views

Delete word highlighted by search

I have hlsearch activated. Sometimes I search for terms I want to correct or delete via / and then selecting for the individual instance via n. Is there a command to delete the current word on which ...
user avatar
  • 103
-1 votes
1 answer
24 views

Automate joining lines in text blocks (perhaps with SHIFT+j) but do not join blocks [duplicate]

I have the lastest versions of arch and nvim which I am using. I have a text that looks like this the slow brown fox jumped over a bridge the blind brown fox stumbled upon a badger ...
user avatar
  • 531
0 votes
2 answers
23 views

search and replace block to a line

I would like to replace a multiline block to one line for example : if (... ){ //comment0 line1 line2 } some code if (... ){ //comment0 line1 line2 } ...
user avatar
0 votes
1 answer
86 views

Multiline search and replace with quickfix list and :cdo

I'm working on applying doctrine/coding-standard on doctrine/orm, and I would like to work smarter. I would like to search occurences of /** * @Id * @Column(type="integer") ...
user avatar
  • 143
2 votes
0 answers
21 views

Vim replace repeating pattern [duplicate]

I got this repeating pattern, but when trying to replace it in vim like: %s/<pat>\_.*<\/pat>// It will replace from first to the very last . How to replace these pattern by pattern? My ...
user avatar
0 votes
0 answers
29 views

:noesckeys in vim.basic giving anomalous behavior in ubuntu 20.04

As reported in this post, I've upgraded to ubuntu 20.04, and am seeing anomalous behavior in vim.basic In addition to the one reported there, I'm now having problems with the noesckeys setting. My ...
user avatar
  • 625
2 votes
3 answers
115 views

Copy command on first letter of each line until end of file

Please forgive me, I'm relatively new to Vim. I'm editing my .vimrc file. I'm adding the following lines: nnoremap <up> <nop> nnoremap <down> <nop> nnoremap <left> &...
user avatar
  • 205
1 vote
1 answer
77 views

replace int following the string

I have this code, id1 = item.check([[-10, -10, a1, b1], [10, 10, a1, b1]]) id1 = item.check([[-10, -10, a1, b1], [10, 10, a1, b1]]) id1 = item.check([[-10, -10, a1, b1], [10, 10, a1, b1]]) id1 = item....
user avatar
  • 113
2 votes
1 answer
385 views

Replace embeded escape code in text

I am using the most recent nvim in arch. I have this text showing in my text doc customerâ<80><99>s the <80><99> appears in blue. The text should read customer's I wish to ...
user avatar
  • 531
1 vote
2 answers
633 views

Replace regex group in nvim

I'm using the most recent version of nvim on arch. I have sentences in my text like this The brown fox I wish to use this format :%s///g to replace all lines starting \nlowercase letter + rest of ...
user avatar
  • 531
0 votes
2 answers
403 views

VI replacing 1 character between two double quotes

I have a 200,000+ line file that I need to update. My issue is that I need to use commas to separate the fields; however in the original file there are commas placed in the "comment section."...
user avatar
3 votes
1 answer
45 views

Need a functionality behaving like Replace on text but for Pasting Blocks

One of my vim usages is to do sketches of topologies in networking I've found the script Draw it really really useful for that So I can draw things like this by pasting these boxes +------+ |ROUTER| ...
user avatar
3 votes
1 answer
307 views

How to move a csv column

Suppose a classic csv like this (each number represents an alphanumeric sequence) : 1,2,3,4,5,6,7 1,2,3,4,5,6,7 1,2,3,4,5,6,7 I was trying to move the 6th column of each line to the beginning of the ...
user avatar
1 vote
1 answer
334 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-...
user avatar
7 votes
3 answers
8k views

Select multiple words, one at a time, then replace them all

Goal: Select multiple words, one at a time, then replace them all. I'm new to Vim; I come from Visual Studio. I would like to achieve one important feature that helped me a lot in my productivity: ...
user avatar
  • 191
1 vote
1 answer
326 views

Custom key binding for project-wide search and replace using FZF.vim Rg function?

I know that one can do a project-wide search and replace using the results of an Rg search in FZF.vim by doing the following: Run :Rg SEARCH_TERM Use Alt + a (or in my case, Esc + a, since I'm using ...
user avatar
  • 177
1 vote
1 answer
58 views

How to switch the order in which objects appear

I have a custom command in a TeX file which takes two inputs A and B, let's call it \operation{A}{B}. I want to find all of the instances of \operation where the first entry A starts with the string ...
user avatar
  • 187
0 votes
3 answers
98 views

Is it possible to exchange search patterns in vim?

Is there a way, built-in or with a plugin, that I can swap any number of two different patterns on an arbitrary range using a regex? Maybe something :s-style like :{range}exchange/{pattern-1}/{pattern-...
user avatar
  • 13
2 votes
1 answer
49 views

text replace problem when target contains '&' symbol

I tried to replace if(cond1) with if(cond1&&cond2) in vim, so I typed the command :%s/\Vif(cond1)/if(cond1&&cond2)/g but the result is if(cond1if(cond1)if(cond1)cond2) and not if(...
user avatar
1 vote
2 answers
50 views

How to replace everything between PORT= and )

I have a (copy of) oracle listener log, and would like to replace the portnumber in every line. These are always of the form (PORT=1234) with sometimes 4 and sometimes 5 numbers. So an exampleline, ...
user avatar
  • 11
4 votes
4 answers
220 views

Plain search and replace like Notepad?

I am aware of the substitute command and of its usage as an ex command :%s/<old>/<new>/g However when <new> contains a very complicated string, say a complicated URL with lots of ...
user avatar
3 votes
1 answer
1k views

Date change question: Find and replace with wildcards?

I have a file with a bunch of dates of the form a/b/c, where a,b, and c are numbers of varying character length. However, I'd like to change every instance to read c/a/b. I'm wondering if there is a ...
user avatar
  • 187
0 votes
1 answer
88 views

inserting a line number into substitution text

I have a long script file that I need to run in an application. I generally create these by running a query against the application and then creating the script I need using VIM. Sometimes these can ...
user avatar

1
2 3 4 5