Non-greedy replacing in vim


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Non-greedy replacing in vim
# 1  
Old 07-24-2012
Non-greedy replacing in vim

I have the following lines:

Code:
{color:#000000}blabla{color}
{color:#000000}moreblabla{color}
{color:#000000}even more blabla{color}

I tried the following line in vim to get rid of all the {} tags:
Code:
:%s/{.*\{-}}//g

But vim complains: "invalid command"

What am I doing wrong?

EDIT: this worked:
Code:
:%s/{.\{-}}//g


Last edited by awayand; 07-24-2012 at 02:57 AM.. Reason: solved
# 2  
Old 07-24-2012
Hi.

Try:

Code:
:%s/{[^}]*}//g

# 3  
Old 07-24-2012
Thanks!

I actually just removed * and that also worked:

Code:
:%s/{.\{-}}//g

# 4  
Old 07-24-2012
So it does!

That must be a "vi thing". Personally, I'd stick to the RE version.
# 5  
Old 07-24-2012
What is "RE version"?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Vim :f

Can someone please tell me what this does? :f word I thought that was the way to save files with a different name but after a quick google search I saw it was like this. :w filename (4 Replies)
Discussion started by: cokedude
4 Replies

2. Shell Programming and Scripting

Non-greedy pattern matching in shell script

Hi all, Is Perl included by default in Ubuntu? I'm trying to write a program using as few languages as possible, and since I'm using a few Perl one-liners to do non-greedy matching, it's considered another language, and this is a bad thing. Basically, I'm using a Perl one-liner to grab XML... (3 Replies)
Discussion started by: Zel2008
3 Replies

3. UNIX for Dummies Questions & Answers

sed non-greedy pattern matching with wildcard

Toby> cat sample1 This is some arbitrary text before var1, This IS SOME DIFFERENT ARBITRARY TEXT before var2 Toby> sed -e 's/^This .* before //' -e 's/This .* before //' sample1 var2 I need to convert the above text in sample1 so that the output becomes var1, var2 by... (2 Replies)
Discussion started by: TobyNorris
2 Replies

4. Solaris

Very Importan - Vim Settings - Error while opening a File using vim

I downloaded vim.7.2 and compiled the vim source . Added the vim binary path to PATH (Because iam not the root of the box) when i load the file using vim it throws me an error Error detected while processing /home2/e3003091/.vimrc: line 2: E185: Cannot find color scheme darkblue line... (0 Replies)
Discussion started by: girija
0 Replies

5. Shell Programming and Scripting

non-greedy sed

I found a sed example that works for me, however, now i would like to understand what it is doing: $ echo "<b>foo </b >bar" | sed 's/<*>//g' foo bar the part that i don't understand is the * my guess is that ^> means the first instance of > stop matching but why * and how is it able to... (2 Replies)
Discussion started by: adambot
2 Replies

6. UNIX and Linux Applications

Help with Vim

How do I use compilers and syntax highlighting in (g)Vim? Specifically, I need a Common Lisp compiler and a C++ compiler. Thanks in advance! (Note: Disregard my other topic.) (1 Reply)
Discussion started by: led3234
1 Replies

7. UNIX for Advanced & Expert Users

About Vim

Hello, what is the maximum size of a file that we can open using vim. (3 Replies)
Discussion started by: nagalenoj
3 Replies

8. UNIX for Dummies Questions & Answers

Need some help with vim

I use vim for writing code. I was using nano but found that vim is a much advanced editor. I am trying to achieve something like this: When trying a loop or a function, I generally type: function name() {} Now when I take my cursor one position to the left and press the return key, it give... (4 Replies)
Discussion started by: Legend986
4 Replies

9. Solaris

Vim 7.0

I want to install VIM 7.0 from sunfreeware.com onto a server. The security guys are giving me a hard time because they found this security vulnerability. http://xforce.iss.net/xforce/xfdb/6259 This vulnerability came out in 2001, and it looks like it was mostly for linux, but I cant be... (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies
Login or Register to Ask a Question