Download presentation
Presentation is loading. Please wait.
Published byZoe Hancock Modified over 8 years ago
1
1 Day 4 Introduction to VI
2
2 Vi – Visual Editor Used to edit text files on a UNIX system –Now also available for Windows/Mac etc. Very powerful for editing text files –Allows you to do everything you can do with MS-Word and more, without ever taking your hands off the keyboard. –Takes a little while to get used to it. Does not use your mouse, so don’t expect that to do anything.
3
3 Editing an new file From the command line, type: –vi –e.g. vi test1 If there is no file in your current directory called test1, this will create the file. If the file already exists, vi will open the file and allow you to edit it.
4
4 3 Modes of Vi Command Mode –This is where you tell VI to do things. e.g. –Remove this line of text –Add the number 0 to the end of this line –Move up a line, Move down a line Insert Mode –This is where you actually type. : mode (ex mode) –This is where you get out of Vi, or save the file.
5
5 In the beginning When you first go into vi, you are in command mode. –Anything you type right now is assumed to be a command. Thus it will probably beep at you, yell at you, or do something odd. To get to the point where you can type, you must go into insert mode. –Do this by hitting the letter: i
6
6 Back to command mode If you need to get back to command mode, you will hit the [escape] button. Remember any commands you try to type while in Insert mode, will end up in your document.
7
7 Command Mode basics Arrow keys move you around (as do k j l j x – deletes a character d – deletes something bigger –e.g. dd – deletes a line dw – deletes a word i – Go back into insert mode a – append text to where we currently are.
8
8 Insert mode basics You should be able to type anything you want. Hit [Enter] to move onto the next line Remember that the arrow keys will NOT move you around while you are in insert mode. [They will put some funny character in your document] The [backspace] key should work just fine as usual
9
9 : mode (ex mode) Saving the file is done by getting into command mode –Hit [Escape] Type: –:w This will save the file and allow you to keep editing it. If you are done, and want it to exit, type: –:wq Which stands for Write and Quit To NOT save the file, and discard your changes: –Type :q!
10
10 Exercise Create a new file in your home directory called: –goldenglobes Type the following into the file: Then save it, and get out of vi The big budget film "Gladiator" won best picture drama at Sunday's Golden Globes. Julia Roberts won best actress in a drama for her role in "Erin Brockovich," and Tom Hanks took the statue for best actor in a drama for "Cast Away." George Clooney won best actor in a comedy film for "O Brother, Where Art Thou?" and Renee Zellweger of "Nurse Betty" won best comedy film actress.
11
11 Millions of other things you can do Copy your goldenglobes file to goldenglobes.bak Now vi goldenglobes again In Command mode type each of these and see if you can figure out what they do: –100ix[escape] –w –e –$ –^ –u –G–a–A–J–G–a–A–J
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.