[vox-tech] serendipity with vim

Ken Bloom vox-tech@lists.lugod.org
Fri, 2 Apr 2004 10:22:56 -0800


This does something completely different. :%s/pattern//g deletes the  
pattern from the lines :g/pattern/d deletes the whole entire line including  
linebreaks.

Supposing I start with a file
xyz abc
yzs abc
ccc bcd
aaa bcd
abc
bcd

if I run :%s/abc//g the result will be
xyz
yzs
ccc bcd
aaa bcd

bcd

if I run :g/abc/d the result will be
ccc bcd
aaa bcd
bcd

if I run :/abc/d (while the cursor is positioned on the first line)the  
result will be
yzs abc
ccc bcd
aaa bcd
abc
bcd

On 2004.04.02 10:00, Mark K. Kim wrote:
> Here:
> 
>    :%s/pattern//g
> 
>    % means "for each line"
>    s means "replace"
>    g means "for all occurrences in that line"
> 
> So without %, it'll replace all occurrences of "pattern" on the line
> you're on.  With % but without g, it'll replace the first occurrence of
> "pattern" for each line for the entire file.  Without % and without g,
> it'll replace the first occurrence of "pattern" only on the line you're
> on.
> 
> Also... instead of %, you can specify the line range inside brackets  
> using
> line numbers (kind of a hassle), or you can select the range you want via
> Ctrl-v before typing ":s/pattern//g" and Vim will figure out the line
> range by itself (really slick).
> 
> -Mark
> 
> 
> On Fri, 2 Apr 2004, Ken Bloom wrote:
> 
> > In sed, one can delete every line matching a pattern with the command
> > "/pattern/d". In vi, using the analagous command ":/pattern/d" only
> deletes
> > the first line that matches the pattern. How do you delete all the  
> lines
> > that match the pattern? ":g/pattern/d"   (:g[lobal] lets you apply an  
> ex
> > command to every line matching a pattern)
> >
> > On 2004.04.02 06:16, Peter Jay Salzman wrote:
> > > heh.  at 6:15 in the morning, it blew my mind.  it took a few seconds
> to
> > > register what was going on.
> > >
> > > if anybody has any vim tips they'd like to share, i'd love to see a
> > > thread of people's favorite vim tricks.
> > >
> > > here's another one i learned just recently:
> > >
> > >
> > > 1 one
> > > 2 two
> > > 3 three
> > > 4 four
> > > 5 five
> > > 6 six
> > > 7 seven
> > > 8 eight
> > > 9 nine
> > >
> > > use line highlighting (shift v) and highlight lines 4, 5, and 6.
> > > type "zf".
> > > you've now "folded" lines 2, 3, 4, 5, and 6:
> > >
> > > 1 one
> > > +--  5 lines: 2----------------------------------------------------
> > > 7 seven
> > > 8 eight
> > > 9 nine
> > >
> > > now use line highlighting to to highlight the first 4 lines.
> > > type "zf"
> > > you've now folded the first four line:
> > >
> > > +--  8 lines: 1----------------------------------------------------
> > > 9 nine
> > >
> > > place the cursor somewhere on the fold.
> > > type "zo" to unfold:
> > >
> > > 1 one
> > > +--  5 lines: 2----------------------------------------------------
> > > 7 seven
> > > 8 eight
> > > 9 nine
> > >
> > > place the cursor somewhere on the fold.
> > > type "zo" to unfold again:
> > >
> > > 1 one
> > > 2 two
> > > 3 three
> > > 4 four
> > > 5 five
> > > 6 six
> > > 7 seven
> > > 8 eight
> > > 9 nine
> > >
> > >
> > > really great for programming.  one of the uses is when i'm editing a
> > > function and need to see another function that's way down in the
> source
> > > file.  i can bring them "close together" by folding.
> > >
> > > previously, i either moved the functions using block cut and copy
> (ick)
> > > or by using vim's marks (better, but still ick).
> > >
> > >
> > > zf: fold the highlighted selection.  it can take movement commands
> too,
> > >    like "zf}" to fold the next paragraph.
> > >
> > > zo: open a fold.  the cursor must be on top of the proper fold.
> > >
> > > zc: refold the last fold.
> > >
> > > what would be nice is if we could have "named folds", like named
> > > registers or named marks.
> > >
> > >
> > > wouldn't mind hearing other people's tips....   :-)
> > >
> > > pete
> > >
> > >
> > >
> > > On Fri 02 Apr 04,  4:43 AM, Issac Trotts <ijtrotts@ucdavis.edu> said:
> > > > On Fri, Apr 02, 2004 at 03:18:36AM -0800, Peter Jay Salzman wrote:
> > > > > it turns out that vim knows what an URL is, and will download the
> > > file
> > > > > pointed to by that URL.  another vim coolity.
> > > >
> > > > Thanks for the tip!
> > > >
> > > > --
> > > > Issac Trotts
> > > > http://mallorn.ucdavis.edu/~ijtrotts
> > > > (w) 530-757-8789
> > > >
> > > > _______________________________________________
> > > > vox-tech mailing list
> > > > vox-tech@lists.lugod.org
> > > > http://lists.lugod.org/mailman/listinfo/vox-tech
> > >
> > > --
> > > Make everything as simple as possible, but no simpler.  -- Albert
> > > Einstein
> > > GPG Instructions: http://www.dirac.org/linux/gpg
> > > GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
> > > _______________________________________________
> > > vox-tech mailing list
> > > vox-tech@lists.lugod.org
> > >
> >
> > --
> > I usually have a GPG digital signature included as an attachment.
> > See http://www.gnupg.org/ for info about these digital signatures.
> > My key was last signed 10/14/2003. If you use GPG *please* see me about
> > signing the key. ***** My computer can't give you viruses by email. ***
> > _______________________________________________
> > vox-tech mailing list
> > vox-tech@lists.lugod.org
> > http://lists.lugod.org/mailman/listinfo/vox-tech
> >
> 
> --
> Mark K. Kim
> AIM: markus kimius
> Homepage: http://www.cbreak.org/
> Xanga: http://www.xanga.com/vindaci
> Friendster: http://www.friendster.com/user.jsp?id=13046
> PGP key fingerprint: 7324 BACA 53AD E504 A76E  5167 6822 94F0 F298 5DCE
> PGP key available on the homepage
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
>

-- 
I usually have a GPG digital signature included as an attachment.
See http://www.gnupg.org/ for info about these digital signatures.
My key was last signed 10/14/2003. If you use GPG *please* see me about
signing the key. ***** My computer can't give you viruses by email. ***