United Bimmer Community - BMW Forum

United Bimmer Community - BMW Forum (http://www.unitedbimmer.com/forums/)
-   Geek Chat (http://www.unitedbimmer.com/forums/geek-chat/)
-   -   Vim Regex (http://www.unitedbimmer.com/forums/geek-chat/6463-vim-regex.html)

komodo 02-20-2006 09:04 PM

Vim Regex
 
Wow, okay, I was just casually programming a macro to go through a few hundred lines and change ten digit phone numbers in a list in vim from 1234567890 format to 123-456-7890 format (adding the dashes in there).

Anyway, I finished, then looked back at the last command I gave vim, and realized to a non-unix person, that would look scary. Here it is:

[code]
.,.+632s/^\(\d\{3}\)\(\d\{3}\)\(\d\{4}\)/\1-\2-\3$/[/code]

Wow, I need to get out and do something else. Something that looks like that should not be able to be rattled off without thinking. :doh

Haha, it worked though. :shades

witeshark 02-20-2006 09:36 PM

That's awesome :type

Rooz 02-20-2006 09:49 PM

:conf

Sie sprechen englisch?

nick_318is 02-20-2006 11:04 PM

Harry I could do that in excel in about 2 minutes without your fancy macro. and in access you could have imported the table and assigned an input mask.

I'm making the assumption that your using an office program. If not, nevermind.

komodo 02-20-2006 11:26 PM

^^ It's not office, it's VIM... a hardcore unix text editing program.

And two minutes would have taken longer. I'm saying I just kinda rambled that off not thinking in about 10 seconds, then looked back and was like "whoa." haha

http://www.vim.org
Quote:

Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems. Vim is distributed free as charityware. If you find Vim a useful addition to your life please consider helping needy children in Uganda.
Hum, for an example of how it's used...

Say you have this situation:

Quote:

the miv system@
This is a test ofunimportant-stuff-here
If you put the cursor at the beginning of the file and type:
Quote:

{down} w w w w {right} {right} {esc} d $ {up} {esc} : s / \ ( . \ ) i \ ( . \ ) / \ 2 i \ 1 / g {enter} {esc} $ x a . {esc} y y d d p {up} {shift} j $
You get this:

Quote:

This is a test of the vim system.
:lol

After you use it for a few years and it becomes natural (not kidding), it looks crazy cool for someone to walk by behind you and see your hands flying around the keyboard hitting random letters and symbols, and the text on the screen is completely warping and changing to whatever you want, haha.

It's an INSANELY effectient word processor though. I absolutely love it, and I do all my programming in it. After you learn vim really well, you can greatly enhance your typing effeciency. No others can touch it. :shades

nick_318is 02-20-2006 11:42 PM

ah very cool

komodo 02-20-2006 11:44 PM

Quote:

Originally Posted by nick_318is
ah very cool

I edited my post. Check it now. :)

witeshark 02-20-2006 11:52 PM

Coding is fun :nod

nightdevils 02-20-2006 11:58 PM

Bah whoever says replacing vim with excel is just plainly wrong... for certain stuff.. unix regexes are world famous, and even ms office utilizes them. but I cant bitch on either side, since I have worked and will work for the opposing forces.

jms 02-21-2006 07:52 AM

I've been using vi (vim's daddy) for at least a dozen years, it is really the only editor (family) to use on *nix (read unix/linux) and even I don't use it to it's full extent. although it did get me a job once. The interview question was:

In vi how do you search and replace every value in a file. (this can be tricky ;) )

nightdevils 02-21-2006 09:03 AM

Sorry I used vi as well. Solaris by default doesnt come with vim :) the question for search and replace is actually quite easy:

: %s/old value/new value/g ... the g for global replace :)

jms 02-21-2006 09:10 AM

Quote:

Originally Posted by ghost
Sorry I used vi as well. Solaris by default doesnt come with vim :) the question for search and replace is actually quite easy:

: %s/old value/new value/g ... the g for global replace :)


You are correct sir,
I would have also accepted
:1,$s/old value/new value/g

that question got me a job as an instructor and of all things for the MCSE course. They also had me developing the unix course, but it never got off the ground.

komodo 02-21-2006 10:37 AM

Quote:

Originally Posted by ghost
Sorry I used vi as well. Solaris by default doesnt come with vim :) the question for search and replace is actually quite easy:

: %s/old value/new value/g ... the g for global replace :)

:nod

nightdevils 02-21-2006 11:39 AM

what a weird mix of bimmer and unix geeks we are! :lol :cheers to the brothas :D

jms 02-21-2006 11:47 AM

^^ I don't know about you but that's what pays for mine :D


All times are GMT -5. The time now is 04:14 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Copyright © 2005-2013 UnitedBimmer.com
Ad Management by RedTyger


Search Engine Optimization by vBSEO 2.4.0 © 2005, Crawlability, Inc.