How do I do a Find and Replace within a selection in vi
?
相关问题
- Replacing more than n consecutive values in Pandas
- Emacs shell: save commit message
- How to change the first two uppercase characters o
- Insert text into current buffer from function
- Find index given multiple values of array with Num
相关文章
- 如何让 vim 支持 .cshtml 文件的代码高亮
- Auto-save in VIM as you type
- How can I use gcc's -I command to add recursiv
- Vim: overloaded mapping for multiple modes
- vi editor is not responding
- How to use relative line numbering universally in
- How to copy the value of a vim option to a registe
- How to specify bold font in VS Code editor?
Some more help here Search and replace in a visual selection
If you want to do a global search and replace (with optional regexes) for all instances in the file, I would do the following:
Omit the g to do a local replace.
Most of the other solutions suggested here work over the ENTIRE line in which the selection occurs, which may not be what you want.
To search and replace ONLY in the selection, first visually select the text, then use a command like so:
This will do the search and replace only in the visually selected section, replacing SEARCH with REPLACE. If you have more than one line selected, this will work over multiple lines too.
Select the text in visual mode (I assume that's what you're doing), then press
:
to start typing a command, you'll see something like this appear in the command line:That means that the command will apply to the selection. Then type
s/search/replace/
and hit enter. (Add ag
after the third slash if you want to replace all matches, and ac
if you want a confirmation for every replace)If you used Visual Mode to select, then:
VIM will place the range (
'<,'>
) automatically if you go into Command Line Mode (by pressing':'
) from within Visual Mode.