LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Replace word in VIM (https://www.linuxquestions.org/questions/linux-software-2/replace-word-in-vim-158763/)

ICO 03-16-2004 10:35 PM

Replace word in VIM
 
I want to replace a key word "BEGIN" to "LEFTCB", and "END" to "RIGHTCB" in a file by using VIM, so how to do it quickly?

cheers

ICO 03-16-2004 10:41 PM

I got it now.

:rs/BEGIN/LEFTCB/a

r - range, can be:
nothing - work on the current line only
number - work on the line whose number you give
% - the whole file

a - argument, can be:
g - Replace all occurrences in the line. Without this, Vim replaces only the first occurrences in each line.
i - Ignore case for the search pattern.
I - Don't ignore case.
c - Confirm each substitution. You can type y to substitute this match, n to skip this match, a to substitute this and all the remaining matches ("Yes to all"), and q to quit substitution.

[WebCarnage] 03-17-2004 01:28 AM

you could also try:

:%s/BEGIN/LEFTCB/g


All times are GMT -5. The time now is 08:51 AM.