DSL Tips and Tricks :: Vim tips



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.

What doesn't work? Perhaps the text you require replacing is different?
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.    :(

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

%g!/F[ a-zA-Z]/s/F\([0-9]*\)/F(\1)/g

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

Next Page...
original here.