Wiki: Tutorial Extentions


<Lars_G> stupid question, I am trying to eliminate blank lines on a file.... tried :%s/^$// and it marks all blank lines but they are not eliminated
<Lars_G> any ideas please?
<p0g> :g/^$/d
<Lars_G> thanks... what is g? never used it before.
<p0g> global
--> zeedo (zeedo@www.bsrf.org.uk) has joined #vim
<-- strull_at_w has quit ("leaving")
<Lars_G> I see, it matches lines based on the regexp and applies command d to them
<Lars_G> interesting...
<MetaCosm> uws: also, changing the tw doesn't excuse the depth :)
<MetaCosm> it just makes it seem less fugly
<Lars_G> thanks, pretty powerfull, a new day, a new command in vim learnt
<p0g> yes, it's where g/re/p comes from :)
<Lars_G> p0g, can regexps be conbined with ranges that way too?
 lampus Lars_G
<Lars_G> something like :5,12/^$/d for example?
<p0g> that would be :5,12g/^$/d
<Lars_G> thanks
<Lars_G> vim rules
<Lars_G> it's so powerfull it's scary
<MetaCosm> Lars_G: yep
<Lars_G> so lets say, ident all non-empty lines from 5 to 12 would be :5,12g/^.+$/<
<Lars_G> ident left
<Lars_G> de-ident actually
<MetaCosm> Lars_G: one thing to be aware of
<Lars_G> yes?
<MetaCosm> after the final /
<MetaCosm> that is Ex commands
<MetaCosm> not "normal" commands
<MetaCosm> but you can fix that by doing
<Lars_G> Not Vi, only Ex? thanks
<MetaCosm> :g/this/normal <
<MetaCosm> that will be normal commands for sure
<MetaCosm> just as you are used to them
<Lars_G> normal changes to Vi(m) mode then....
<Lars_G> thanks
<-- Esaj has quit ("Client exiting")
<p0g> < is an ex command too
<Lars_G> Yes I know what Ex is ;)
<MetaCosm> p0g: well, my example was more for general
<MetaCosm> not the specific command he was using
<Lars_G> yes I understood, thanks for the remark.
<p0g> Lars_G: and :v means "does not match", so you could use :5,12v/^$/<
<p0g> but shifting empty lines doesn't work anyway
<Lars_G> p0g: they're the left sided version of RegExps normal flags then, g, v, does caseless matching apply too? (s i think it was? no... U???)
<Lars_G> p0g, Yes it was a bad example :)
<p0g> huh, left sided version of regexps normal flags?
<p0g> what's that supposed to mean
<Lars_G> g is regexp's flag for global
<Lars_G> :s/soemthing/else/g <----
<tazz> p0g, hmm.. is that about grep true? :)
<p0g> oh, no it's not like that
<Lars_G> ok
<Lars_G> thanks
<p0g> tazz: yes, but it's from ed, not vim
<tazz> Cool.. but why 're'?
<tazz> Could be anything
<p0g> regular expression
<tazz> I see
<Lars_G> Yes I try not to say "grep" not to mention an implementation of regular expressions but the concept of regular expressions themselves...
<Lars_G> :) that's why I walways say RegExps instead of Grep or regs and eregs
<Lars_G> :)
<Lars_G> Or Perl, the world famous bloated RegExp engine ;) (Joke, I respect perl a lot.)

Have you seem this article describing vim for Mac users?: "What Is Vim (It's Easier than You Think)" by Matthew Russell 07/11/2006 http://www.macdevcenter.com/pub/a/mac/2006/07/11/vim-is-easier-than-you-think.html


Copyright © 2007 RobertMelton.com