Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
Unix

Journal nizo's Journal: Oh how I love vi 37

I can edit a 2+ gigabyte text file to delete 2,955,867 lines in the middle of it, and it actually works. Damn slow, but it works.

This discussion has been archived. No new comments can be posted.

Oh how I love vi

Comments Filter:
  • Infact, you were prolly using ed commands to do it.

    vi can barf on stuff big time; especially very long lines.
    • Yeah - try editing /etc/group on a system with 700+ users. It barfs. Spectacularly. That's when you get the pleasure of slapping younger, less experienced SA's on the fingers and tell them to use available system tools (in this case chgrpmem in AIX).
      • I always use the cp for that on an edited copy ...
      • by Tet ( 2721 )
        Yeah - try editing /etc/group on a system with 700+ users. It barfs.

        WTF crappy version of vi are you using? Even that traditional Unix vi (as I believe is found on AIX) could handle that with ease.

        • Agreed, I've edited 2gb files with vi with no issues. Of course, I've nearly always been on Solaris, BSD or Linux.
        • Nono. I can edit 2+GB files no problem. What I can't edit is for instance an /etc/group file with 700+ users in one group (which pushes the line length well over 2048 characters - which seems to be the line length limit for the version of vi I use). Sorry if that wasn't clear.
    • by nizo ( 81281 ) *
      I am sure I could have written a perl script to do it too, but I was feeling particularly lazy this morning. Working on a broken server for 10+ hours with people running around in circles screaming probably had something to do with it too.
    • That's why I really like vi: it was built with a unimodal line processor at its center and made it multimodal based upon either visual or standard line processor inputs. A single session of vi can be viewed as an incremental series of ed calls with visual feedback between each operation.

      But that little bit of projection into human UI space makes all the difference. Pretty powerful model when you think about it :P
  • Emacs can do that, too. (I think.) ;)

    And, it's a perfectly valid operating system. :D

    • by nizo ( 81281 ) *
      Hehe


      Yeah, but in vi I get type stuff like: :4,984392d


      If I was using emacs I would still be looking for my key :-)

      • by mekkab ( 133181 )
        You were indeed using ed.
        • by RevMike ( 632002 )

          He could have done 4G4984388dd :)

          Or, if we are a little sick in the head, 4G4984387Jdd :o

          I once had a 800 MB xml file that needed all the & replaced with &. vim did it before the supergeniuses I was working with managed to get it ftp'd from the server to a machine with WordPad.

          • by mekkab ( 133181 )
            :4G100000Jdd
            ?

            ed doesn't know what you are talking about, and neither do I.
            • by RevMike ( 632002 )
              That is because it is a vi command, not an ed command. :)

              4G - navigate to the forth line.

              100000J - join the line below to the end of this one, 100,000 times.

              dd - delete the current line.

      • [Ctrl]+x, l, 4
        [Ctrl]+[space]
        [Ctrl]+x, l, 984392
        [Ctrl]+w
        Where I've got [Ctrl]+x, l mapped to M-x goto-line.
      • by Tet ( 2721 )
        Yeah, but in vi I get type stuff like: :4,984392d

        Errr... marks? Set mark A on the first line you want to delete, move the cursor to the last line, then d'a

        Much easier than trying to work out (and remember) line numbers. You can, of course, use marks in ex commands, too.

        • by nizo ( 81281 ) *
          Actually I usually note the first line (in this case 4) and then move to the line I want to delete and type: :4,.d
          I never did use marks much; did they even exist in the earliest versions of vi? ^G will tell you which line you are on in vi; the line number is already displayed in vim. Like most unix tools, there are several ways to do anything....
          • by Tet ( 2721 )
            I never did use marks much; did they even exist in the earliest versions of vi?

            They've been there as long as I've been using vi (18 years now).

    • EMACS = Eighty Megs And Constantly Swapping
                     
  • The only thing I hold against UltraEdit is that there is no vi emulation. So, for my vi fix I have to use either this [winvi.de] or this [vim.org] when working under Windows.

  • Chuck Norris uses a paper clip on the parallel port.
  • I use vim for all my programming. Between vim+grep and other unix tools, who needs an IDE?

    • by nizo ( 81281 ) *
      Agreed. vi+(e)grep+awk+sed (or perl :-) ) and I am set to do damn near anything.

      Yes a gui is nice (when it works), but what happens when you want to do something the gui wasn't designed for? Like, say, change something across multiple records? As much as I would like to click through hundreds of records and change one thing (say, area code, which might actually happen here), I would rather dump our ldap database, use vi to make the substitution, and then dump it all back in. Or I could write a perl program

      • by RevMike ( 632002 )
        I'm right there with you. I learned perl first, so I never bothered much with awk and sed. Vim is my ide, and it runs just as well on a hot workstation, an old laptop, a remote server, and a vt220.
        • by nizo ( 81281 ) *
          This is why I learned vi instead of emacs; it used to be back in the old days, every unix machine had vi and you had to install emacs later (SunOS, Ultrix, etc). If you can't install the OS in the first place, no amount of emacs savyness is gonna save your butt :-)
        • by btlzu2 ( 99039 ) *
          perl's for girls!

          you program like a girl. :)
          • by nizo ( 81281 ) *
            Heh, lemme guess.... you like python don't you???? I for one prefer to write all my code with no whitespace whatsoever!!!!!
            • by btlzu2 ( 99039 ) *
              no, i just don't like perl. :) perl is puke.

              still like java and c.

              LOVE vi. ;)
              • by nizo ( 81281 ) *
                still like java and c


                Ahh, a masochist :-) So you don't do any kind of shell scripting at all? Not even bash??? Granted if you are programming 100% of the time you probably don't much of a scripting background, though it can be damn helpful at times. Then again, if you are awk/sed/grep/find savvy, you can probably do most of what you might need scripts for anyway....

                • by btlzu2 ( 99039 ) *
                  you know, i'd rather use sed than perl. the command line tools in unix are SO powerful with the pipe concept and the "many simple tools working together". also, regex is your friend!

                  i'll do the bash script though--pretty handy. i'm doing more scripting these days actually. bash scripting for simple things, java or c for more complicated things.
            • Can't speak for btlzu2 but I like Python. Being able to read your code is a good thing ;)
  • I used to think that people should be forced to demonstrate proficiency with vi before they are allowed on the internet, or at least before they are allowed to post to usenet and listservs.

    OK, I still believe it, but it is too late now.

    Then again, some people might say you should be able to edit text files with cat grep sed & awk (or is it just sed?) something something, or ed.

    No, vi was the pinnacle of editors.

    Every editor should be able to go into a "vi mode."
    • I do edit text files with cat, grep, sed and awk. And do some middlin'-creative mangling on the side (awk's associative arrays are really useful for some things, and are usable by people who haven't the time to learn Perl).

      I doubt that the writers of DO-178B ever had awk scripts in mind, but I've used awk in the process of writing to the standard (mostly, checking my work).

    • no, vi should have a "MS Word mode".

To save a single life is better than to build a seven story pagoda.

Working...