VI/VIM Survival
Results 1 to 7 of 7

Thread: VI/VIM Survival

  1. #1
    Senior Member
    Join Date
    Nov 2001
    Posts
    4,786

    VI/VIM Survival

    (new versions of linux will open up VIM when you enter VI..which is what we'll be dealing with here)

    A win32 version is available Here.

    linux help and man files are very informative...but not very helpful if you're new to linux. when i read the vim man file for the first time i could swear i saw things like..."to capitolize the second letter of the forth word in every third line spin your chair around three time then punch the keyboard". so for the longest time i would just install joe or pico

    below is all you really need to know to use VI/VIM to view/edit ascii files. of course once you've learned to use it there are many more commands and options that will help you use it well. VIM It is a very powerful tool but being as this is for 'basic survival' we will not be dealling with the advanced stuff.



    Viewing/Editing files:


    if you want to view the contents of a file using vim simply type 'vi filenane' at the prompt. filename being the name of the file you wish to open. If the file is in a directory other than the one you are in the path must be included with the file name. You are now in 'VIEW' mode and no changes can be made.

    if you wish to edit this file you'll need to enter 'insert mode' by hitting the 'insert' key on the keyboard. you wll see --INSERT-- appear at the bottom left on your screen. you can now make all the changes you need. use the cursor (arrow) keys on the keyboard to navigate to where you want to make the changes in the document and simply type, delete, whatever.


    when you've finished viewing and/or editing you need to return to view mode...this is done by pressing the 'Esc' key. you'll notice --INSERT-- will be gone.


    Quitting VI:

    Code:
    if no changes have been made            :q and press enter 
    
    to save changes                         :wq and press enter
    
    quit and not save                       :qa! and press enter
    so if you find yourself typing in a file you didn't want to be typing in simply enter :qa! and no harm will have been done

    NOTE: the ':' must be typed along with the letter/s of the command



    Creating Files:

    The easiest way to creat a new file is simply add the name you want to give the new file as an argument to vi (vi newfilename), enter insert mode, put what you want into the file, switch to view mode (Esc) then save the changes (:wq). a simple ls will show newfile listed there and a 'cat' will show the text you added are in that file.

    you can also create a new file by just opening vim, entering insert mode, put in what you want, return to view mode (Esc) then put the name you want to give this file after the write/quit command (:wq newfile).

    there is one more feature id like to cover. although its a little beyond survival it can make life allot easier.

    if your need to change one string a long .conf or script... while in view mode type the string preceeded by a foward slash (/somestring). as you are typing you'll notice the letters typed are being highlighted at the first location that contains them all. when you get to the full string where you want to make the change, hit enter to be in insert mode at the spot. make your changes then write and quit.

    To get help while in insert mode hit <F1>, while in view mode use either F1 or enter :h

    ok! let's do a quick exercise.

    at the prompt enter 'vi test' (without the quotes). Now hit Insert and type 'this is not a test'. get out of insert mode by pressing 'Esc' the save and quit by entering ':wq' (no quotes...anywhere)

    you should be back at the prompt.

    now again type vi test. you'll find the text you typed earlier has indeed been saved in the file called test that you created.

    now type '/not' hit enter then hit insert. hit del three times then type 'just'. press 'Esc' to leave insert mode, save the changes and exit

    a quick 'cat test' should show you your changed sentence.

    congrats! your now a vi user. well not a very advanced one but a user just the sam and we got to start somewhere.
    Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”

  2. #2
    Banned
    Join Date
    Jun 2003
    Posts
    1,302
    nice write up... But, not really up to your own personal standards of excellence... Nice none-the-less... I wish you would of explained more about Vi and vim, but it's a decent beginner work...

  3. #3
    AO BOFH: Luser Abuser BModeratorFH gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177
    You went way easier on him than you did me.
    Kill the lights, let the candles burn behind the pumpkins’ mischievous grins, and let the skeletons dance. For one thing is certain, The Misfits have returned and once again everyday is Halloween.The Misfits FreeBSD
    Cannibal Holocaust
    SuSE Linux
    Slackware Linux

  4. #4
    Banned
    Join Date
    Jun 2003
    Posts
    1,302
    This is his first **** up... You continually **** up... and then **** up again after we tell you we don't want anymore damn tutorials on installing a distro...

    He just messed up this once with short info...

    Hm.. I think I am going to write another tutorial sometime soon...

  5. #5
    Senior Member
    Join Date
    Nov 2001
    Posts
    4,786
    Sorry whizkid2300 and gore. i wrote what i wish would have found when i was trying to use vi. i didn't do it to up my tut count or anything but if you think AO deserves more then ill get after it and add more to it...in the orginal post if its not closed for editing or as a reply if it is...thanks!
    Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”

  6. #6
    Super Moderator
    Know-it-All Master Beaver

    Join Date
    Jan 2003
    Posts
    3,914
    Hey Hey,


    Here's a vi cheatsheet that I made a while back for one of my Linux classes.. I rather like it.. I've attached it to threads in the past, but since this one is related here it is again.

    Peace
    HT
    IT Blog: .:Computer Defense:.
    PnCHd (Pronounced Pinched): Acronym - Point 'n Click Hacked. As in: "That website was pinched" or "The skiddie pinched my computer because I forgot to patch".

  7. #7
    Banned
    Join Date
    Jun 2003
    Posts
    1,302
    Tedob I am not saying the tutorial is bad, I am simply saying that compared to your normal works... It's a piece of ****...

    You have some of the best written tutorials I have seen on this site, and compared to those this explains very little... It's an alright right up for any beginner to VI....

    I guess I was expecting more with your track record...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides