LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-10-2005, 08:17 AM   #1
fssengg
Member
 
Registered: Feb 2005
Location: Kerala(God's own country)
Distribution: Redhat-8
Posts: 35

Rep: Reputation: 15
Question replace a word in vim editor


hai
I am using vim editor and i want to know how can i replace all occurance of a word with an other word? is there any built in command in vim to do this?
 
Old 03-10-2005, 08:24 AM   #2
jxi
Member
 
Registered: Feb 2003
Location: Richmond VA
Distribution: Slackware 11 -- CentOS 4.4
Posts: 115

Rep: Reputation: 15
you have help in vim

while in command mode try:

:h replace
 
Old 03-10-2005, 08:26 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

In command mode:

:%s/THIS/THAT/g

This will change all instances ofTHIS in THAT. the % is the line range (% = all), you could also do this: 5,15, which will change occurences in lines 5 to 15 (included).

The g on the end makes sure that all occurences in one line are changed. If you don't use the g, only the first instance will be changed.

Take a look here for a short vi tutorial: vi tutorial

Hope this helps.
 
Old 03-10-2005, 08:39 AM   #4
fssengg
Member
 
Registered: Feb 2005
Location: Kerala(God's own country)
Distribution: Redhat-8
Posts: 35

Original Poster
Rep: Reputation: 15
thankx for ur help it solved my problem
 
  


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
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
Replace word in VIM ICO Linux - Software 2 03-17-2004 01:28 AM
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 01:28 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