Questions tagged [replace]
Overwriting text with the r or R commands. For search-and-replace operations, use the [substitute] tag.
263 questions
1
vote
2
answers
112
views
How can I replace (almost) all newline characters in a single paragraph?
I have many files with lists of words like this:
list
word1
word2
word3
word4
which I would like to transform to a single line, like this
list
word1, word2, word3, word4
I would like to do this ...
1
vote
1
answer
65
views
Remove needless repetition of words from a text including repeated words with apostrophes
This expression, run interactively within Vim:
:%s/ \v(\w+('\w+)*)\_s\1/ \1/gi
It removes needless repetition of words.
In this way it turns this:
the the it it them them it's it's then then and this ...
1
vote
3
answers
376
views
How to print yanked data in replace mode?
I want to paste data from clipboard. But instead of insert the data, I want to overwrite (like using R).
1
vote
1
answer
88
views
How can I replace duplicate line prefixes with blanks?
Is it possible to transform:
John Apple Red 3
John Apple Green 5
John Radish White 2
John Radish Red 7
Tom Apple Red 3
Tom Apple Green 5
Tom Radish White 2
Tom Radish Red 7
to:
John Apple Red 3
...
0
votes
5
answers
1k
views
Replace pattern with user input for every occurrence on the line
I'm a new Vim user, so please bear with me.
A while ago I wanted to be able to replace a pattern with user input, and I stumbled upon this question on StackOverflow, and its answer worked beautifully.
...
1
vote
3
answers
478
views
How to replace hex encoded string with chars?
I have UTF-8 encoded HTML with id(s) and href(s) encoded as hex values like %D0%B0%D0%B1 or .D0.B0.D0.B1. Can I convert such strings into readable form using Vim?
-1
votes
1
answer
28
views
Why the quote is placed at the beginning of string?
To match the string behind the : :
TE: trailer
The expression will convert the string into trailer:
:1s/\v(.{-}):\s{1,}(.{-})/\2/
Why 1s/\v(.{-}):\s{1,}(.{-})/\2""/ convert the string ...
1
vote
2
answers
1k
views
How to grab visual selection for search, but apply the appropriate escapes?
In this clip,
From visual mode here after selecting im.g.mat I trigger my vnoremap <m-/> y:%s/<c-r>0//g<left><left> bind.
The purpose of this bind is to initiate a global file ...
3
votes
1
answer
76
views
Vimscript to replace persian/arabic digits with english ones
I have a file that has so many persian/arabic digits in it. I would like to replace them with their English counterparts. How is that possible?
0
votes
1
answer
518
views
Match/find and replace all series of tab characters with one tab
I have a tsv file that has the header separated by tabs but each row is separated by one or more tabs. The parser/viewer I'd like to use doesn't understand that the values are separated by a series of ...
0
votes
4
answers
578
views
Replace every character on a visual selection with a register's character
I'll try to illustrate as clear as I can.
Suppose I have the following text open in vim/nvim
_________
| |
| 9999 |
| |
---------
If select 9999 visually and then hit r8, this ...
1
vote
0
answers
35
views
How to swap every two words in the whole text?
I have such codes:
int flag1 = GetWidget(widget);
flag1.append(widget);
delete widget;
I'm willing to swap every flag1 and widget in the whole text, i.e.:
int widget = GetWidget(flag1);
widget.append(...
2
votes
1
answer
5k
views
Delete all text before a specific character using vim
I have used curl to grab a website's code and put it in a text file. I'd like to delete all text that isn't a link! Lucky for me, all links are inside quotes, so I just need to delete all lines ...
0
votes
1
answer
42
views
target for number between two different special characters
I have the following string, where I want to change the number "merged_boris_20220712.boris". If instead of underscores it had dashes, I would just go to the numbers and do ciw and type the ...
1
vote
1
answer
103
views
Using an inoremap with `r`
I have some inoremap's in my vimrc, such as
inoremap \c <c-v>u2705
which enters a ✅ emoji for when I am writing checklists.
However, I noticed that while I am able to use it when in insert mode ...
1
vote
1
answer
62
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 ...
0
votes
1
answer
2k
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 ...
1
vote
1
answer
73
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 ...
0
votes
1
answer
98
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 ...
3
votes
2
answers
626
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 ...
5
votes
1
answer
2k
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 ...
2
votes
3
answers
667
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"]
...
0
votes
1
answer
736
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 ...
0
votes
2
answers
84
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 ...
1
vote
1
answer
47
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 ...