Vi - Linux Editor
Can A Text Editor Be Evil?
The vi editor comes with every version of Linux or Unix. It's a terribly unfriendly beast of an editor, but you should know about it because someday you're likely to find yourself on a system where you have no other choice but to use it. A friend of mine calls vi the Heart of E vi l, but that might be just a bit harsh--you decide. Using vi is similar to using other editors in that you can see your file on the screen (this is not the case with a line editor, for example), move from point to point in the file, and make changes. But that's where the similarities end. Cryptic commands, a frustrating user interface, and the absence of prompts can all drive you up a wall. Still, if you focus on a few basics, you'll get the job done.Command and Input Mode
The hardest thing to understand about vi is the concept of modes. When using vi, you're always in either Command or Input mode. Unfortunately there's no clue as to which mode is currently active. In Command mode, you can move the cursor, search for characters, and delete existing text. But to enter or edit new text, you have to switch to Input mode.
When you start vi, you're in Command mode. To enter Input mode, type the letter a (lowercase only) to signal that you want to add text after the cursor position. Press esc to switch back to Command mode at any time.
Here's how to create a file from scratch using vi. To start, create a new file named cow.joke by typing
vi cow.joke
You'll see a screen that looks like this:
|
~
~
~
~
~
~
~
~
~
"cow.joke" [New file]
Adding New Text to Your File
Your cursor (the vertical bar at the top of the figure below is in the upper-left corner of the screen, and the message at the bottom tells you that a new file called cow.joke was just created. The tilde characters in the first column are just placeholders for empty lines.
Now press the letter a to enter Input mode and type the lines shown in here. Press enter at the end of each line to go on to the next.
Jane: Knock, knock...
Bill: Who's there?
Jane: The Interrupting Cow.
Bill: The Interrupting Cow wh...
Jane: MOOOOOO!
|
~
~
~
~
"cow.joke" [New file]
Saving Your Work
So far, so good--let's save this little masterpiece. You're still in Input mode, so press esc to enter Command mode; then type ZZ (to put your file to sleep). You won't see any Z's on the screen, but after you've entered the second Z, your file will disappear, your Linux command prompt will return, and you'll see this message, indicating that your file was successfully saved:
"cow.joke" 6 lines, 113 characters.
Congratulations--you've just survived your first encounter with vi. You know that the a command switches to Input mode, esc gets you back to Command mode, and ZZ saves the file, but you'll have to expand this limited repertoire to get any real work done.
Common vi Commands
Have a look at this list of common vi commands (there are many more, but these will at least allow you to get some basic work done). Then we'll do one more exercise before moving on.
Note: As with all of Linux, vi commands are case sensitive.
Positioning the Cursor
Entering Input Mode
Entering Command Mode
Exiting or Saving Your File
Trying Out Some vi Commands
Here's another example to try out some of the vi commands. Enter the following command to fire up vi again, and you should see the file as we left it in the last example:
vi cow.joke
Changing Text
Let's change Bill's name to Biff on the second line. To do so, use the arrow keys to position your cursor on the third character of line 2 (the letter "l" in Bill); then press x twice (to delete the two l's). Now press i (to enter Input mode) and then type ff to complete the change from Bill to Biff.
Tip: Be careful about pressing the arrow keys while you're in Input mode. In some versions of vi you can position the cursor only in Command mode. Yuck.
You could also have used the R command to do this job of replacing text, so use it to change the other Bill now. Press esc to enter Command mode; then type /Bill to search for the word Bill. The cursor should move to line 4, right to where Bill is located.
Now position your cursor on the third character (the letter "l"), press R to replace the characters, and type ff. Both Bills should now be Biffs.
Adding and Deleting Lines
Here's how to add or delete a line. Press esc to enter Command mode; then press the o key to add a new line. You're in Input mode again, so you can type whatever you like on this new line. But that would ruin the joke, so delete this new line by pressing esc and then entering the dd command. The line you just added should go away.
Quitting without Saving Your Changes
Hmmm. . . . "Biff" just doesn't have that wholesome ring to it, so let's forget about all the changes we've made in this editing session and exit vi without saving the file. Make sure you're in Command mode, enter the :q! command, and then press enter. Your Linux prompt should return, and the cow.joke file will be just as it was before.
Parting Words about vi
Using vi can be frustrating, but it really isn't rocket science once you get used to the concept of the two modes and get the hang of when it's okay to move your cursor or enter text. If you're ever unsure about which mode you're in, simply press esc once or twice, and you can be sure you're in Command mode.
There are some powerful (but arcane) commands that diehard vi users use to get things done quickly in this relic-of-the-sixties text editor. The man vi command will tell you a lot more about vi if you decide you want to become proficient.
The Usenet newsgroup comp.editors is a good place to discuss vi or ask questions. You can find the vi FAQ (Frequently Asked Questions) file on the Web at http://www.faqs.org/faqs/editor-faq/vi/.
For more information on the vi command, see the vi manual.
Previous Lesson: Linking Files
Next Lesson: The Emacs Editor
Comments - most recent first
(Please feel free to answer questions posted by others!)
ICQ 586-179-503
tel:+380958561468
Íàòàëüÿ
2ÐÌÒ24ÊÏÝ19Øn¨)1(Ëi¼br /> 2ÐÌÄÒ14OÝ4Øn¨)1(Ëi¼br /> Ðàçúåì ïèòàíèÿ 7 êîíò. (ï) øàã 3,96 ïà ïëàòó (PWL-7)
ÑÍÖ23-4/141 Ðàçúåì
ÐÐÑ3-50-7-1-¼br /> ØÐ36Ó4ÝØn-Ê
Êîííåêòîð äëÿ ñîåäèíåíèÿ ñâåòîäèîäíîé ëåíòû (ïàðà)
10-0067 b AL red ðàçúåì 7äí
ÑÍÖ28-32/27±B ãðóïïà Ðàçúåìû ---14448
2ÐÌÒ39OÍ45î¨)1(Ëi¼br /> 2ÐÌô2OÝ30ØnÅ1(2)(i
ØÐ16Ï2ÍØ5Í 86ã ðîç.êàá íèêåëü Êîííåêòîð Õàðêîâ
TNC-êîííåêòîð íà RG-58 îáæèìíîé (TNC-C58P) (TNC-7401A) (GT-205A)
ÐÏÌØ1-45-Î2 ãðóïïà Ðàçúåìû ---10527
2ÐÒÒ16ÊÓÝ2ó¼br /> TFT FG050701DWSWBGL2 Íåîáì ðàçúåì è øëåé 33êîíò., øàã 0.5ìì Çàïðîñ DI
2ÐÌÒ33ÊÏÝ7Øn¨)1(Ëi¼br /> ÑÐ50-283Ô ÑÎÅÄÈÍÈÒŘ Ðu0004ÈΗu0011ÒΒÍÛÉ. 1990-2010 ÎÄ.
ÌÐ1-50-3¼br /> ÑÍÖ13-102/27Ð-1-à(á,â,ã,ä,å)(Ó)¼br /> ÎÍÖ-Ðí09-24/27Ð1(2,3,11,12,13,14,15)Q
Ðàçúåì 2(ì) äëÿ ïàéêè íà ïëàòó 2 ìì (PBD-6N) (PBD-2 2
ÐÐÑ6-50-0-2-¼br /> 4-141, Ðàçúåì BNC "øò" ìåòàëë íà êàáåëü RG-59, SAT-602, íàêðóòêà
Ðàçúåì ALPINE 7524 à/ìàãí.
53097
I am hoping you have already found the answer to your question but i noticed none were given here so I thought I'd give it a go.
yum install vi
will give you 'no package found'
there are different versions of vi !
<vi> and a newer enhanced version <vim>
yum install vim-minimal provides vi
yum install vim-enhanced provides vim
many pages explain the diffs, but if you are used to vi I would go with vim-minimal.
Happy Day
the package you need to intall is
lt0831sm
And how can i download and install wine for windows applicaions compatibility?
i wanna to run an graphics program in centos5 but everytime it could show the error graphics.h could not open plz give me the solution for this problem and plz tell me how to run an graphics programme using vi editor if there is any other option expect using cc or gcc
I was working with the text editor nano, but now I play the vi text editor, and I stab complicated by lack of information.
I'll be arriving queries thank you very much.
not a moment too soon, as I suddenly was able to resist the urge to stick a fork in my eye that using vi always inspires.
how about if i want to quit after i have saved my file
UK
pelase help me ....
E37: No write since last change (add ! to override)
:w write
:q quit without saving
:q! prompt quit without saving
Actually the UNIX spec requires an editor that is compatible with vi. In Linux this is usually VIM.
If a link called "vi" is used to launch vim it will behave as Vi rather than as vim (same is true for 'ex'), which is why most distros use an alias for vim that is called vi.
Plz sent me the full script of vi.
thanks for it
I am using vi editor on Linux-64 (Red Hat). After saving a file (!w) it simply hangs instead coming back on insert mode. I had to kill the job and reopen it to edit the file. Any ideas, what's happening?
Thanks
thanx for providing us a great introductory knowledge of vi editor in linux.......
I am new on our page. can you please teach me shell scripts.
It is very clear to understand...
Thank's for ur hardwork..........
please sending me a basic Linux and vi editor commands.am the beginner.kindly please help me regarding the above .hope u.
I like it.
I appreciate your effort!!
Thanks.
You can't even imagine all things Vim or Vi can do.
rayninfo.co.uk/vimtips.html
Best,
Jozsef
E138: Can't write viminfo file /home/sustenance/.viminfo!
providing us such type of basic and easy to understandable commands
mk --> Mark the beginning of the text to be copied
"ay'k --> Copies text upto this line into the "clipboard"
"ap --> Inserts the copied text from the line below the cursor
I use vi on a daily basis. I can't tell you how many times I have enjoyed the power of vi when it comes to text processing. Take character substitution or insertion for example.
It is one of the main reasons I am so hooked on VI as a Linux/Unix sysadmin.
I frequently use this type of command
:12,43 s/Charles /John /g
to replace all instances of Charles with John between lines 12 and 43. Try that kind of precision with Word or other programs.
VI, although created in the old days, has power that few modern word processors can even approach. You just have to take the time to use it and let it grow on you. Soon, it will change from being VIle to VItal to your sysadmin job.
Thanks for sucha wonderful tutorial.
Thanks a lot
BTW, I love this website!
thanks
I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But
don't ask me to send what you already have. :-) NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Copyright © by -
All rights reserved - Redistribution is allowed only with permission.

