Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (6) </ 1 2 3 4 [5] 6 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Vim tips< Next Oldest | Next Newest >
jpeters Offline





Group: Members
Posts: 804
Joined: April 2006
Posted: Dec. 20 2007,00:51 QUOTE

Quote (lucky13 @ Dec. 19 2007,14:41)
Quote
I was looking through lucky's cheatlink for a way to search & replace using wild characters (* or ?)

Grrr, off the top of my head I can figure out the search. The replace string needs work (e.g., it's changing F1 to F(d)). Off to google...

:%s@F\d@F(\d)@g

This can't be too difficult.

Edit: Especially if you do what hats suggested. The digit range (\d) will work for [0-9].

I'll play around with this when I get some time, or else enquire on a vim forum.

Quote

Edit: Especially if you do what hats suggested. The digit range (\d) will work for [0-9]


That was about the first thing I tried, but didn't work.
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Dec. 20 2007,01:15 QUOTE

What doesn't work? Perhaps the text you require replacing is different?
Back to top
Profile PM 
jpeters Offline





Group: Members
Posts: 804
Joined: April 2006
Posted: Dec. 20 2007,02:35 QUOTE

Quote (^thehatsrule^ @ Dec. 19 2007,20:15)
What doesn't work? Perhaps the text you require replacing is different?

I didn't know you expected it to work as is.  As posted, it doesn't match. Eliminating the first set of (), it yields an illegal back ref error.

Edit: I'm checking through a few pages now on pattern matching in vim.


http://www.vim.org/htmldoc/pattern.html

EDIT:  Hmm...Now it  works!  Thanks HATS....I have no idea why it didn't work before, since I pasted it in.  (I guess I needed to go through the page I posted to see WHY it works before it would work.....)  :D
note: perhaps I hadn't included the range previously....

EDIT: The '+' doesn't seem to work for getting additional digits, but a '*' does. Thus, '1,20s/F\([0-9]*\)/F(\1)/g'  ,for replacing in lines 1-20.  

EDIT:  After trying it out further, I found that it's also putting () after every 'F' that doesn't have a number. e.g, F(100) F()r some F()cking reason.    :(
Back to top
Profile PM 
jpeters Offline





Group: Members
Posts: 804
Joined: April 2006
Posted: Dec. 21 2007,02:36 QUOTE

Here's a work-around, although there must be a better way!

%g!/F[ a-zA-Z]/s/F\([0-9]*\)/F(\1)/g
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Dec. 21 2007,02:46 QUOTE

You have to escape the + with a \
The * wildcard stands for zero or more instances of a group.

EDIT: that link you posted explains that as well
Back to top
Profile PM 
27 replies since Dec. 10 2007,08:11 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (6) </ 1 2 3 4 [5] 6 >/
reply to topic new topic new poll
Quick Reply: Vim tips

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code