LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 03-16-2004, 10:35 PM   #1
ICO
Member
 
Registered: Aug 2003
Location: ~/.
Distribution: CentOS
Posts: 290

Rep: Reputation: 30
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
 
Old 03-16-2004, 10:41 PM   #2
ICO
Member
 
Registered: Aug 2003
Location: ~/.
Distribution: CentOS
Posts: 290

Original Poster
Rep: Reputation: 30
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.
 
Old 03-17-2004, 01:28 AM   #3
[WebCarnage]
Member
 
Registered: Jun 2003
Location: USA
Distribution: Slackware 9.1 | netBSD 1.6.2
Posts: 35

Rep: Reputation: 15
you could also try:

:%s/BEGIN/LEFTCB/g
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
find and replace answer word? matarodi Linux - General 0 10-27-2005 01:51 PM
replace a word in vim editor fssengg Linux - Newbie 3 03-10-2005 08:39 AM
Help - how to find and replace in Vim stardotstar Linux - Software 7 10-14-2004 11:31 PM
vim search and replace - split line phreak7t7 Programming 2 08-16-2004 05:02 PM
How to replace a word within a file elegantly Linh Programming 3 10-23-2003 10:21 AM


All times are GMT -5. The time now is 06:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration