Questions tagged [replace]

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

Filter by
Sorted by
Tagged with
10
votes
3answers
536 views

Is there a motion similar to a" that never includes leading whitespace?

I'm using the a" motion rather often in vim; e.g. using ca" while refactoring a piece of code to replace a hardcoded argument with a variable name. The problem with this approach is that a" includes ...
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 ...
4
votes
1answer
1k views

Change '\r' to '\n' for search and replace?

In expression :s/foo/bar\n/g When replacing \n inserts a null byte, according to the docs I have to use \r. Since I insert newlines more frequently than null bytes, is there a way to change this ...
1
vote
1answer
790 views

vimrc Line Placing me In Replace Mode

I have the following one-line ~/.vimrc file: Line 1/1: nnoremap <silent> <ESC> :nohlsearch<CR><ESC> Whenever I edit a new document, now, I am placed immediately in Replace ...
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 ...
2
votes
2answers
99 views

How to replace patterns after line k

The command :%s/foo/bar/gc is to replace all "foo" by "bar" in the global field with confirmation. There are many "foo"s in my file within first 50 lines not to be changed. How can make this command ...
1
vote
1answer
3k views

How to find every occurrence of a word and append some text to it?

I have to find a word and append some other text to in in Vim: for instance I have to append to every occurrence of the word "public_html" the text "/Text-Analysis-Tool" to obtain "public_html/Text-...
15
votes
2answers
10k views

How to partially replace text in a selected text-block?

Not easy to find a nice title for my problem. I'm aware of inserting in front of a text-block: Ctrl-v select lines I type text ESC Now I would like to do this but also with replacing a part in my ...
2
votes
1answer
420 views

Move back the cursor after a “cw” command

I use quite a lot cw to change a word. I put the cursor on the start of the word, then cw followed by the new word and then <esc>. So far, so good. My problem is that after that the cursor is ...
3
votes
1answer
1k views

How can I search and replace within multiple files? [duplicate]

I have the same text that I want to replace in multiple files (say, I'm updating version numbers in multiple files). Even using the command history to reuse commands, it sure is tedious to open each ...
10
votes
2answers
493 views

Most efficient way to replace the entire buffer?

Currently, I have two similar methods to replace the entire buffer with some other text (say in clipboard). Method #1: delete all lines: :%d. paste text: "+P ( or similar: :put+). Method #2: ...
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 ...

1 2 3 4
5