Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-02-2006, 12:53 PM
|
#1
|
|
LQ Newbie
Registered: Nov 2004
Posts: 19
Rep:
|
vim search and replace only one line
Quick vim question. Most versions of vim that I've been on usually replace globally without having to specify /g. Is there a flag to specify "replace only on the line where the cursor is"?
Thanks
|
|
|
|
11-02-2006, 01:05 PM
|
#2
|
|
LQ Veteran
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 8,691
|
Hi,
The g is not used to indicate multiple lines, but for making it global on one line, I.e:
String is: abcabc
s/a/X/ will return => Xbcabc
s/a/X/g will return => XbcXbc
Line ranges are:
<none> only on line where cursor is on.
5,15 => line 5 up to and including line 15
4,$ => line 4 to end
.,$ => from line where cursor is on to end.
Combined:
12,$s/a/X/ => from line 12 to end replace all first found a's on line.
Hope this clears things up a bit.
|
|
|
|
11-02-2006, 01:16 PM
|
#3
|
|
LQ Newbie
Registered: Nov 2004
Posts: 19
Original Poster
Rep:
|
Thanks for your reply!
So when I run :%s/^\s*// on:
and my cursor is on the 2nd line, I should get this:
correct?
But I get this:
Do I have some other configuration set that I don't know about?
|
|
|
|
11-02-2006, 01:36 PM
|
#4
|
|
LQ Veteran
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 8,691
|
Hi,
Quote:
|
Originally Posted by hakmed
Thanks for your reply!
So when I run :%s/^\s*// on:
and my cursor is on the 2nd line, I should get this:
correct?
|
Incorrect.
% is short for 1,$ (or 0,$ if you like), which is the whole file.
:s/^\s*// is all you need if you want to target the line the cursor is on. You don't need to include an address (line) range.
Hope this helps.
|
|
|
|
11-02-2006, 11:33 PM
|
#5
|
|
LQ Newbie
Registered: Jun 2006
Posts: 3
Rep:
|
This may be a bit old of a posting but I'll add my two cents also....
... another option to target line two, in your example of:
is
|
|
|
|
11-07-2006, 07:13 PM
|
#6
|
|
LQ Newbie
Registered: Nov 2004
Posts: 19
Original Poster
Rep:
|
Excellent. Thanks everyone!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:36 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|