Questions tagged [replace]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
20 views

Don't jump on search and replace

How do I get my cursor to not move to the last thing it replaced after a search and replace. No <C-o> or extra key presses. Is there some autocmd magic I can setup to listen on any substitute ...
1
vote
1answer
26 views

Seach and replace with special characters

I am trying a search and replace because I am using some macros in my code. I want to replace tb.DUT.genblk4[0].U_rap_cisfd_wrapper this with `RAP_CISFD_WRAP_I in vim. I tried using :%s/tb\.DUT\....
1
vote
1answer
19 views

How do I map multiple replace commands in visual mode

I'm trying to edit my init.vim to allow quick, custom retabbing with one key. My current attempt is as follows (the replace text in the last command is a tab character inputted in insert mode): ...
3
votes
1answer
86 views

Replace from the current position to the end of the line

Is there a way to search and replace replace from a specific position in the line to the end of this line? I am here and you are there ^ I tried to show cursor position with ^. For instance,...
0
votes
1answer
21 views

How to update vim on centos7?

By default, the version of vim on centos7 is 7.4. I want to update it to vim 8. There are some questions with 'https://copr.fedorainfracloud.org/coprs/mcepl/vim8/repo/epel-7/mcepl-vim8-epel-7.repo -o /...
0
votes
1answer
59 views

Inserting a square bracket as part of search and replace

I have the text pattern [2] in a text file. I want to replace it with the text string '[1]'. Using the command: :%s/\<[2]\>/[1]/ only replaces the string '2' in the square brackets so the ...
1
vote
2answers
46 views

Keep next letter in replace mode?

If I'm using replace mode, but I want to keep one or a few characters in a row of the text I am replacing, is there an easy way to skip forward rather than retyping the characters or exiting replace ...
0
votes
1answer
60 views

Can I select and paste with a single operation?

Here's my use case. I have the following text: This is a [hyperlink](http://someurl.com). Now I want to replace the http://someurl.com text with a new URL in the default register (something I've ...
1
vote
3answers
65 views

Search for line and paste as column until next match

I'm wondering if this is possible, more for curiosity's sake, but also it might be useful to know. I have several ascii data tables and I want to combine them all into a single file. So I combined ...
3
votes
1answer
47 views

How to replace the first matching for each line with regular expression

Saying that I have such a file as below: <random_string>hello<random_string> random_string<random_string>hello<random_string> I want to remove the first square bracket and ...
0
votes
2answers
32 views

How do I map a sequence of letters in insert mode?

After trying to make this work: Map a sequence of letters in insert mode I can’t get the correct answer to work. Is it still working? Can anyone post a working .vimrc file? I want to get this: When ...
1
vote
2answers
45 views

Replacement in visual mode

I wrote a function for selecting a text region and replacing in it certain predefined characters: fun! Tstrepl() range s/\%Va/\="\u2227"/ge " 'a' to '∧' s/\%Vb/\="\u2228"/ge " 'b' to '∨' ...
2
votes
3answers
79 views

Replace a string with a variable containing newline characters

I have a file that looks similar to this: module.exports = { blank: { area: 'frontend', name: 'Magento/blank', locale: 'en_US', files: [ 'css/styles-m',...
1
vote
1answer
49 views

Substituting (*x).y with x->y

I am coding a C project and as I am unexperienced, everytime I needed to access the element of a pointer to a struct I typed (*x).y (where x is a struct and y an item), which I just realized could be ...
0
votes
3answers
53 views

How to search in beginning of line and add something at end of that line

I want to search lines beginning with certain string in Vim, and then add something at the end of file. I have tried the following but it removed everything instead of appending :%s/^12138/*...
1
vote
2answers
43 views

How to replace a string only if the line starts with another string

I need to find ONLY the lines that start with the string G1 Z, and then replace any occurrence on that same line of F1800 with a new value of F500. For example: G1 Z9.800 F1800.000 ; move to next ...
2
votes
4answers
85 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
33 views

How do I replace all occurances of a string with a large amount of text?

I modifying a gcode file with custom toolswap codee, and I need to replace every instance of "T0" (^T0$) with a large amount of text (19 lines), which is stored in a separate file. How can I do so ...
1
vote
1answer
19 views

how to add a word two lines above certain word in multiples places

my text look like this in several places of the file: FDE PW91k XCNADD PBE ::FULLGRID END END eor and I want to introduce a word two lines above "eor" word throughout. I have tried :,.-2/eor/...
1
vote
1answer
88 views

Exclude folder when searching files in working directory

I'm working in a react project and opened vim from the root folder. When I'm using :vimgrep /pattern/ ** I just can search everywhere, but I want to search everywhere except the 'node_modules' ...
3
votes
2answers
321 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
1answer
70 views

vim argument substitution inside a function

I would like to use the arguments passed to a function, as an argument to replace a search. Something like this: function! Myfunction(...) %s/hello/ goodBye a:1, a:2/g endfunction Does anyone ...
1
vote
1answer
36 views

Find and replace in XML file in vi

I have an .xml file which contains many times the following web beacon <span lang="EN" class="multilang">ANY TEXT TOTO</span> I would like to make a "Find&Replace": each web beacon ...
0
votes
1answer
73 views

regex find and replace all with capture groups throws E488: Trailing characters

My text file looks like this Lastname, Firstname Doe, John I'm trying to get it to end like this using find replace regex Firstname Lastname John Doe This regex throws the error, although using ...
1
vote
0answers
30 views

Change a word with a N repating characters where N = word length

I have some code that I want to 'censor'. For example, I have secret token in a source code 1f85ez and I want to replace it with xxxxxx Now I do it with viwrx command. Is there way to make such a ...
2
votes
0answers
31 views

Substitute regex group in prompt when replace with confirmation

I am using vim to replace with simple regex: %s/Foo\(.\)/Bar\1Biz/gc I wanna to confirm each occurence and Vim asks: replace with Bar\1Biz (y/n/a/q/l/^E/^Y)? Is it possible to substitute group (\1) ...
1
vote
2answers
43 views

Replace all integers until a certain character

I am making a table which has chemical formulas in the first column so I need the integers as subscripts to use it in a LaTex file. I want to transform CH4 & to CH$_4$ &, C2H5 & to C$_2$H$...
4
votes
1answer
170 views

Replace With Text From The Line Above?

I have a text file like this: ge-0/0/45.0,First-Floor-Security,13 ,Voice_First_Floor,18 ge-0/0/46.0,First-Floor-Security,13 ,Voice_First_Floor,18 ge-0/0/47.0,AV-Media,155 ,Building-Automation,75 ,...
0
votes
1answer
61 views

How to replace seconds with hours:minutes:seconds?

With milliseconds; before: 64.173 I want to get: 00:01.04.173 Another example: from 23032.3 I want to get this: 06:23:52.3
3
votes
1answer
58 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 ...
1
vote
1answer
82 views

Adding a quantifier to group

I have the following file (I used 4 spaces instead of tabs here): abc123 abc123 abc123 abc123 abc123 abc123 abc123 kaskls abc123 kaskls The alphanumeric entries are separated ...
0
votes
3answers
57 views

Append `0,` to all lines having 2 commas and not more than 2 commas?

I have a file 0,3, 7,2,0, 1,2,3, 1,2, which should be 0,3,0, 7,2,0, 1,2,3, 1,2,0, So how can I append each line with two commas with 0,? I am interested in the most elegant solution and ...
1
vote
2answers
90 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
2answers
90 views

iedit behaviour in Vim?

For Emacs there is idedit. It Allows you to select some text, then hit one button, which automatically select all other occurrences of the selected text in the current buffer. Then you can edit the ...
1
vote
0answers
42 views

change ofWord to of Word, and ignore offer, office, off etc

I OCRed a document but has this problem: some spaces between "of" and the word after are gone and I need to add a space between "of" and "word". Is there any way to do it? And also to avoid adding ...
1
vote
1answer
32 views

In visual mode, how do I bind a key so that the selected text generates “%s/<SELECTEDTEXT>/<CURSORHERE>/g”?

In visual mode, how do I bind a key so that the selected text generates %s/<SELECTEDTEXT>/<CURSORHERE>/g ? Preferably ; considering I never use it otherwise. Thanks.
0
votes
1answer
82 views

Is it possible to return to normal mode in the middle of a vim command?

By simply calling :(range)g/bob/norm Axxx I can add xxx to the to the end of all lines in range containing bob. Is there a way to return to normal mode after having used A/I/a/i to enter insert mode, ...
1
vote
2answers
106 views

Delete from end of line in visual block mode

If i've got the code hello hellllo hello i can insert code before or after all of the lines by using I or A in visual block mode, respectively. How can I delete the last x characters? I'm aware ...
3
votes
4answers
214 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\(....
0
votes
2answers
54 views

how to replace N characters without having to press <esc>, is it possible?

In command mode, r replaces the character under the cursor by the one pressed right after typing r without going into insert mode, so there's no esc to press. 5r replaces the 5 characters starting ...
2
votes
2answers
466 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
2answers
487 views

Add prefix to numbers at beginning of each line

Should be straight-foward but cannot get it working. I have a text file that has numbers at the beginning of some lines. For e.g: 1. Some text.... running to many lines 2. Some more text ... 3. A ...
0
votes
1answer
20 views

How to automatically return to where the cursor was before executing cdo?

Is it possible to automatically return to where the cursor was before running :cdo command? Currently, the cursor ends in the last file in the quickfix, then I have to navigate back to where I was ...
1
vote
2answers
74 views

Change Case of last searched pattern

I often use # key to quickly search for a keyword. I want to change the case of the last searched pattern in the easiest possible way. One way to do this is to use \U\1 in the substitution part and ...
0
votes
1answer
51 views

Replace a line with two other lines

I have multiple files with a string like: source /PATH/TO/OLD/ENV.sh And this needs to be replaced with: source /PATH/TO/NEW/ENV1.sh source /PATH/TO/NEW/ENV2.sh Usually, I use sed to replace ...
0
votes
3answers
158 views

How to suppress the error {Error detected while processing BufRead Auto commands for “*”}

I want to alter existing files automatically,to replace all tab with four blanks in existing file. vim .gvimrc autocmd BufRead * exec "%s/\t/ /g" The error info pop up when to open a file ...
3
votes
1answer
309 views

How do I start overwriting visually selected text without c

I would like to start overwriting immediately visually selected text without any additional keystrokes such as c. I am looking something similar to normal text editor where you can straightaway ...
0
votes
1answer
40 views

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

@saginaw answered a question I asked a long time ago, in this thread. Here's a code snippit of his suggestions that illustrates my problem: function! s:PadMacro(type) abort if a:type ==# 'char' ...
2
votes
1answer
91 views

Convert a search and replace to a function

Given this search and replace expression, which works fine on one or multiple visually selected lines: :'<,'>s/\v.{-}(`.{-}`).{-}(\\'.{-}\\').*/$this->execSQL('DELETE FROM \1 WHERE id = \2;')...
0
votes
2answers
79 views

vim: replace n strings with another strings

After reading https://stackoverflow.com/questions/7338794/vim-regex-replace-with-n-characters, I've known how to replace tabs by spaces: :%s/^\v(\t)*/\=repeat(repeat(' ',4),strlen(submatch(0)))/g ...