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
| ® | Move cursor one space right. |
| ¬ | Move cursor one space left. |
| | Move cursor up one line. |
| ¯ | Move cursor down one line. |
| ctrl-F | Move forward one screen. |
| ctrl-B | Move backward one screen. |
| $ | Move cursor to end of line. |
| ^ | Move cursor to beginning of line. |
| :1 | Move to first line of file |
| :$ | Move to last line of file |
| / | Search for a character string. |
| ? | Reverse search for a character string. |
| x | Delete the character at the cursor position. |
| dd | Delete the current line. |
| p | Paste data that was cut with x or dd commands. |
| u | Undo. |
Entering Input Mode
| a | Add text after the cursor. |
| i | Insert text before the cursor. |
| R | Replace text starting at the cursor. |
| o | Insert a new line after the current one. |
Entering Command Mode
| esc | Switch from Input mode to Command mode. |
Exiting or Saving Your File
| :w | Write file to disk, without exiting editor. |
| ZZ | Save the file and exit. |
| :q! | Quit without saving. |
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.
風俗
デリヘル
風俗
デリヘル 風俗
エロゲー
ソープランド
吉原 ソープランド
出会い
出会い
デリヘル
すすきの ソープラン
ド
新宿 ソープランド
千葉 ソープランド
埼玉 ソープランド
神奈川 ソープランド
吉原 ソープランド
sod
バイブ
風俗求人 高収入
都内 キャバクラ 全額日払い
無料動画
無料動画
大阪 風俗
大阪 風俗
神戸 風俗
裏DVD
裏DVD
風俗 求人
風俗 求人
デリヘル 新宿
デリヘル 東京
千代田区 デリヘル
台東区 デリヘル
墨田区 デリヘル
中央区 デリヘル
Posted by alex — 14 Oct 2009, 19:07
サイト制作
アートメイク
エクステ
アパレル
アロマセラピー
ダイエット クエン酸
ダイエット サプリ
レストラン ウェディング
ランコム
エスティローダー
ルナソル
神社
ワイン
赤ワイン
シャンパン
ダイエット 方法
ダイエット 運動
競馬 ゲーム
競馬
SPUR
シュプール
コーディネート
防災グッズ
ペット 用品
SEO
格安 SEO
マキアージュ
MAC
コスメデコルテ
インプレス
クラランス
エスト
オバジ
インターシグナル
アスタリフト
サロン
事業再生
クレジットカード 現金化
Posted by alex — 14 Oct 2009, 19:10
和歌山 デリヘル
神戸 デリヘル
姫路 デリヘル
大阪 デリヘル
京都 デリヘル
大阪 デリヘル
神戸 デリヘル
和歌山 デリヘル
奈良 デリヘル
京都 デリヘル
神戸 デリヘル
姫路 デリヘル
奈良 デリヘル
京都 デリヘル
大阪 デリヘル
大阪 デリヘル
Posted by alex — 14 Oct 2009, 19:12
和歌山 デリヘル
神戸 デリヘル
姫路 デリヘル
大阪 デリヘル
京都 デリヘル
奈良 デリヘル
大阪 デリヘル
神戸 デリヘル
和歌山 デリヘル
奈良 デリヘル
京都 デリヘル
神戸 デリヘル
姫路 デリヘル
和歌山 デリヘル
奈良 デリヘル
京都 デリヘル
大阪 デリヘル
南大阪 デリヘル
大阪 デリヘル
Posted by alex — 14 Oct 2009, 19:14
payday ok loans faxing no interest on first payday loan payday loan washington cash advance america payday loan Seattle consolidate payday loans pay day loan advance pay day loan company no teletrack no credit check no fax payday advance private student loans carquest auto parts magnum payday advance advance america cash express payday loan no fax sonic payday loan best no fax payday loan Please, send your abuse here!!! send.your.abuse.here@gmail.com
Posted by rhejjxm — 22 Oct 2009, 15:45
advance pay loans quick online payday loans cash loan payday loan store milwaukee payday loan yes loans payday loan Fort Worth online payday loan no fax check cashing locations nyc sonic payday loan quickpayday debt consolidation payday loan without a checking account make fast cash guaranteed bad credit payday loans no fax cash advance credit card bank cash loans online payday loans Louisville Jefferson County instant no credit check no fax payday loans sonic payday land cash loan faxless payday loan instant approval cash loan companies check in advance ace check cashing locations check cashing locations los angeles ca cashnetusa payday advances payday loan store illinois cash advance fee hsbc
Posted by liissfr — 22 Oct 2009, 22:41
cash advance usa united cash loans phone number pay day one lender hershey kisses nutritional information online payday loans quick payday advance loan payday advance locations payday loans New Orleans payday loans in phoenix area united check cashing locations in new york debt consolidation loans paycheck advance omaha nebraska payday loan store chicago il payday loan San Francisco cash advance loans no fax ace cash advance employment payday loans no faxing no teletrack pay day payday loans Phoenix bad credit credit cards no fax cash advances ameracash long term loans payday loan no faxing no credit check cash advances wired
Posted by aqljsgn — 25 Oct 2009, 20:45
halloween inflatables halloween crafts halloween movie halloween halloween sounds halloween desktops kids halloween party supplies halloween 9 Halloween Gifts halloween food Halloween Gifts halloween masks halloween facts Halloween skeleton halloween tombstones halloween clipart halloween printables jack o lantern halloween invitations halloween coloring pages halloween props halloween games halloween pumpkins halloween ideas halloween 9
Posted by szzyyst — 27 Oct 2009, 01:40
payday loan Milwaukee urgent cash loans paycheck advance nebraska bad credit paycheck advance easy online personal loans 1 hour payday loans guaranteed payday loan check cashing store nj interest calculator payday loan Detroit sonic payday loans payday uk review pay day one fort worth tx paperless payday loans moneytree merchant services personal loans debt consolidation auto parts stores cash advance america houston fast cash ideas check city faxless payday loan overnight payday loans no credit check no faxing absolutely guaranteed bad credit payday loans magnum payday loan cash advance online
Posted by maeemzm — 28 Oct 2009, 02:17
no fax cash advance magnum payday advance low fee pay advances cash lenders yellow pages payroll advance online payday advance uk instant payday advance loans online pay day advance payday game 24 hour check cashing stores cash advance loans no fax long term payday loans second chance no fax payday loans cash advance american payday loans Tucson ace check cash express houston tx secured loans advance america payday usfastcash cash advance fee visa instant no fax payday loan direct lender faxless quick payday loans
Posted by wmspfjn — 28 Oct 2009, 21:39
ontario 49 winning numbers payday loan no faxing payday express omaha instant online cash advances payday select cash loan cash advance america houston no faxing payday loan instant faxless payday loans online ace check cashing places in dc unemployed tenant loans pawn america cash advance credit card processing online approval for payday advances cash advance america lender payday candy bar payday loans San Antonio bad credit student loans online cash advance companies payday mail de cash advance fee visa quick guaranteed personal loans cheap cash till payday payday loans in uk secured personal loan rates hershey foods stock
Posted by bhounrj — 30 Oct 2009, 01:03
biggest cash payday loans 24 hour check cashing services payday loan lenders direct instant online payday loan lubbock guaranteed personal loan ace check cash express locations in virginia payday loan store chicago il instant payday loan cheap payday loans predatory payday loans payday loan cash advance locations in california payday loan people bad credit 1000 no fax payday loan cash advance locations in miami my payday loan yes fees cash advance america locations payday loans online without fax express check advance not a payday loan ace check cash express houston texas payday loans no checking account required hershey pennsylvania quick no faxing payday loan check cashing services at walmart payday loan cash advance
Posted by pggzuew — 01 Nov 2009, 01:05
biggest cash payday loans 24 hour check cashing services payday loan lenders direct instant online payday loan lubbock guaranteed personal loan ace check cash express locations in virginia payday loan store chicago il instant payday loan cheap payday loans predatory payday loans payday loan cash advance locations in california payday loan people bad credit 1000 no fax payday loan cash advance locations in miami my payday loan yes fees cash advance america locations payday loans online without fax express check advance not a payday loan ace check cash express houston texas payday loans no checking account required hershey pennsylvania quick no faxing payday loan check cashing services at walmart payday loan cash advance
Posted by hvrzuto — 01 Nov 2009, 21:06
payday loan store milwaukee cheapest payday loans check n go jobs payday loans Philadelphia federal student loans ameriloan payday loan contact number sonic payday land login online instant cash loan discover personal loans check cashing services portland oregon best online payday advance loans payday loans chicago il payday ok loans online pay advance wholesale hershey bars my pay day ok paycheck advance companies payday loan trap no faxing online payday loans cash advance no faxing online payday loans cash advance no faxing online payday loans cash advance payday loan store indianapolis power ball cash loans online ace cash advance locations ace cash express
Posted by moxoqqv — 03 Nov 2009, 21:55
pay day one easy online cash advance check advance payday loan easy cash loans check cashing fees new york best rated cash advance loans online debt consolidation loan calculator check cashing scams payday loans no debit card needed home loan lender moneytree merchant services online payday advance loans in los angeles instant faxless payday loan california check cashing stores llc payday loans canada instant faxless payday loan instant online no fax payday loans ace check cashing centers jobs ace cash advance employment application ace check cash express houston locations cash loans online cash advance payday loan payday loans in uk payday loans in canada cash advance american express card
Posted by tfqmztp — 06 Nov 2009, 01:44
small personal loans ontario 49 winning numbers check cashing store fees payday lenders online california check cashing stores stockton ca online payday loan arizona online approval for payday advances payday loans online bad credit sonic payday loans faxing bad credit instant auto loan payday loans for bad credit no faxing cheap no fax payday loans payday loans work check cashing store nyc payday loans online uk refinance loans for bad credit instant faxless cash advance paycheck advance omaha hours payday uk quidco instant online no fax payday loans payday loans Kansas City cash lenders california check cashing locations check cashing service payday loan no faxing cheap check cashing delaware
Posted by ffidvec — 06 Nov 2009, 21:31
sonic payday advances hershey candy bar birth announcements secured personal loan rates payday lending cash advance loans online online payday loan las vegas bankruptcy auto loans unsecured loans for unemployed paydayone reviews hershey chocolate gifts quick payday and payday select loans hershey white chocolate instant approval personal loans unsecured personal loan rates payday loans washington online payday loan online no fax payday loans no direct deposit payday loan debt relief western union locations unsecured business loans cash advance fee visa ace cash advance employment application check cashing usa miami payday loan store illinois payday loans uk ltd
Posted by aaigdaf — 07 Nov 2009, 21:38
sonic payday advances hershey candy bar birth announcements secured personal loan rates payday lending cash advance loans online online payday loan las vegas bankruptcy auto loans unsecured loans for unemployed paydayone reviews hershey chocolate gifts quick payday and payday select loans hershey white chocolate instant approval personal loans unsecured personal loan rates payday loans washington online payday loan online no fax payday loans no direct deposit payday loan debt relief western union locations unsecured business loans cash advance fee visa ace cash advance employment application check cashing usa miami payday loan store illinois payday loans uk ltd
Posted by bufdnvz — 08 Nov 2009, 01:08
NYIK3t cphluayaanrj, [url=http://wrkelzcwbtmx.com/]wrkelzcwbtmx[/url], [link=http://sgzyfoblclyw.com/]sgzyfoblclyw[/link], http://zecmbdkpbwlc.com/
Posted by qbdwba@hentny.com — 08 Nov 2009, 16:03
payday one arlington tx my space quick payday advance loan ace america cash advance check cashing store florida pep boys auto parts the check cashing store locations check cashing store nj check advance no teletrack gary coleman diff rent strokes amscot check cashing locations christian personal loan companies payday loans online payday advance loans magnum cash advance no teletrak payday loans payday loan lenders only fha loans dex online no fax payday advance quick payday loans payday advance paydaymax coupon ace america cash advance payday loans bad credit no faxing payday loans Los Angeles 24 hour check cashing stores in los angeles
Posted by yvtubcv — 09 Nov 2009, 00:36