Questions tagged [replace]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
29 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 ...
0
votes
1answer
32 views

How to change word within snake-case-variable?

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 ...
0
votes
1answer
427 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 ...
1
vote
1answer
135 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 ...
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 ...
-1
votes
1answer
9 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 ...
0
votes
2answers
21 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 } ...
3
votes
3answers
1k 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: ...
0
votes
1answer
39 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") ...
2
votes
0answers
18 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 ...
0
votes
0answers
23 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 ...
2
votes
2answers
397 views

Replace last instance of character (and there's more)

I am trying to format a list that uses tabs for indentation so it will render as a bulleted list on Confluence. That means that each instance of a tab needs to be replaced with an asterisk (*), plus ...
2
votes
1answer
64 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 ...
2
votes
3answers
68 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> &...
1
vote
1answer
57 views

How to add a certain word before the names of methods in Javascript?

I am working with react. First I had a component with state I created methods and all that. Now I want to convert it into stateless component. I have add the word function before each method name. ...
1
vote
1answer
31 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....
1
vote
2answers
212 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 ...
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 \...
0
votes
2answers
62 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."...
3
votes
1answer
38 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| ...
3
votes
1answer
59 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 ...
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-...
8
votes
2answers
2k views

How do I use 'cgn' for word under cursor?

I really like and often use the cgn command for replacing something I was currently searching for, but it sort of lacks a (imho) rather intuitive feature: replace the word (or whatever) under the ...
2
votes
3answers
211 views

How to select a block in visual mode and delete this block and immediately enter insert mode?

for one single word, the job is quite easy: we just do a 'cw' what if I select a certain text and I want to replace this block with one word? obviously I can do a 'x' and then 'i', is there a one ...
1
vote
1answer
32 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 ...
0
votes
3answers
56 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-...
2
votes
1answer
45 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(...
1
vote
2answers
27 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, ...
4
votes
4answers
128 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 ...
3
votes
1answer
333 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 ...
4
votes
1answer
123 views

Replace all quotes with escaped quotes and vice versa

I am trying to replace all quotes (") with escaped quotes (\") and simultaneously all escaped quotes with normal quotes. I found the following solution to a similar problem here for swapping 'foo' to ...
0
votes
1answer
35 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 ...
0
votes
2answers
67 views

Define a new ex command active only in specific filetype (C++)

I would like to define a new command for C++ files/buffers (ft=cpp). I shall explain the requirements through the example below. The newly defined command :stripdbg should strip the surrounding dbg() ...
12
votes
3answers
24k views

How to add space on multiple lines when pressing spacebar (without extra configuration)?

I tried visual block, but visual block only allow to highlight or delete characters on multiple lines. Is there any function that allows to add space before the first character of multiple lines when ...
5
votes
1answer
91 views

Vim find/replace highlighting

I'm a long time Vim user but a few months back started dabbling in Emacs. One of the things I really liked about Emacs was when doing a find/replace s/you/me it would highlight the word I was ...
1
vote
1answer
30 views

Can we make substitutions based on rules from a file?

I've been using the command mode for making replacements in a file. Something like :%s/foo/bar/g and to make a series of replacements: :%s/i/1/g | :%s/j/2/g | :%s/k/3/g | :%s/l/4/g | ... This line ...
2
votes
3answers
127 views

How can I repeat the cgn sequence?

Recently I learned the awesome command cgn to repeat a change to a word. I’ve seen several answers advising its use, like this: What is the best way to re-factor a variable name in vim? and this: How ...
2
votes
3answers
3k views

Select WORD under cursor

I know that * selects the word under the cursor, but what if I want to actually select a WORD ? Just to be clear, I would then like to use the selection for a replace, something like :%s//foo/g
2
votes
1answer
15 views

Change words but retain format and character casing

What is the most convenient way to do search and replace for same words in multiple formats. I often find myself doing tons of regular expressions as follows. :%s/scubaDiver/deviceDriver/g :%s/...
0
votes
1answer
36 views

global search and replace on all lines that don't begin with a backslash

I'm trying to globally enclose in {}'s all instances of +,-,= that aren't already so enclosed. But I don't want to do this for lines that are latex commands. Since my latex commands are all on ...
1
vote
1answer
31 views

How to insert text using substitute and regex?

Honestly I can't read regex for now. I have quick-fix list and I have a hunch that this can be done with regex but I don't know how. I want this: @ViewChild(MatTable) @ViewChild('text 1') @...
11
votes
10answers
1k views

Simultaneous find and replace

Is there a way to perform a simultaneous find and replace? e.g.: I want to replace all 1 for 0 and simultaneously all 0 to 1 [ [1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 0, 1], [1, 1, 1, 0, 1, 1], ...
0
votes
1answer
58 views

How can I create mappings for replace mode?

I know how to create key mappings in normal mode using nmap and in insert mode using imap. However I do not know how to create mappings in replace mode. I would assume it's either rmap or Rmap, but ...
1
vote
3answers
179 views

How to delete everything except urls?

I have string like this: 1668955,,, bunch of text</figcaption><br /><a href="https://the_url/article_detail.php?article_id=10003414" target="_blank">w..... </a><br />&...
1
vote
4answers
48 views

Vim invert block of text over an axis

I was wondering what would be the most Vimish way to the following: I want to invert the text on the right side of the equal sign to the left (and the left to the right). For example, I want this: v1 ...
0
votes
2answers
224 views

Decode URL (percent decoding)

Other editors I have used are able to decode URLs. For example these can take a string like this: https://nim-lang.github.io/Nim/osproc#waitForExit%2CProcess%2Cint and produce this: https://nim-...
-2
votes
1answer
102 views

Replace in a loop

I have a buffer that contains this sentence : I go to a rendez-vous this evening. and I have this function : function MyFunction() let myList = ["rendez-vous"] let myFile = readfile(bufname(1)) ...
1
vote
1answer
20 views

How can I replace a word while keeping the original casing?

Basically: cat -> horse CAT -> HORSE Cat -> Horse I know this is underspecified (e.g. unclear what cAt should become). However, is there a canonical solution for this?
-1
votes
2answers
93 views

How to replace spaces inside a selection

I have this text : He's a self made man who gets what he wants. The small blue forget me not flower was first used by the Grand Lodge. And this function: function MyFunction() let myList1 ...
1
vote
1answer
40 views

Search and Replace - How do you change a specific string across syntactically similar files?

I'm attempting to write a Vim macro that will allow me to replace a single variable of a single service across multiple Icinga configuration files. Services are syntactically very similar so I ...

1
2 3 4 5