免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1134 | 回复: 0
打印 上一主题 下一主题

Using Vi [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-03 17:53 |只看该作者 |倒序浏览

Why Should I use VI?
A good question. vi is one of the oldest editors around yet it is still very popular today. One of the reasons it is still used is due to its efficiency as an editor. The key benefit is that you do not need to use the mouse at all when editing a document. Taking your hand off the keyboard to move the mouse to a position in the document and then moving your hand back to the keyboard is extremely inefficient. With vi, your hands never leave the keyboard.
How Do You Invoke The vi Editor
From a linux shell, type:
vi
where  is the name of the file you want to edit. If the file doesn't exist, it will be created. Exiting vi is discussed below.
There are two modes to the vi editor.
  • Editing mode
  • Command mode
    Edit Mode
    The editing mode is quite simple. Whatever you type appears in the buffer or document. Whatever you type is echoed back to you in the buffer. Pretty simple.
    To enter editing mode, hit I for insert. There are other ways to drop into editing mode, which will be explained below, but just remember I for now.
    Command Mode
    The command mode however is where all the magic happens. It allows you to execute a series of commands on your document to help you edit it. Whether that be moving the cursor, replacing text, finding text, or whatever; you can do it all in command mode. All without using your mouse!
    When you first open a document in vi, you always start in command mode. If you are in editing mode and want to return to command mode, just press ESC.
    When editing or writing a document in vi, expect to jump between editing mode and command mode often. It will become second nature after a while.
    Command Mode Commands
    The rest of this document will explain some of the more useful commands available in command mode.
    In command mode, the following key sequences have the specified effect:
    First off, these keys are essential:
    h - move cursor left one position
    j - move cursor down one line
    k - move cursor up one line
    l - move cursor right one position
    The arrow keys move the cursor in vim which is what Mandriva actually installs when you install vi. So if you attempt to move the cursor with the above key codes and they don't work, then try the arrow keys.
    Always remember, that if there is something you want to do in vi, there is probably a command or way to do it. Also, there is always more than one way to do something. You'll find that principle everywhere in engineering and science.
    Here are some simple commands you will use in addition to the movement commands above:
    i - Change into editing mode. Remember, hitting  gets you back out.
    dw - Delete the word or rest of the word under the cursor.
    cw - This command is like 'dw' except that it drops you into editing mode upon completion.
    x - Deletes the character directly under the cursor.
    . - Repeat the previously executed command.
    :w - Save the current file to disk ('w' stands for "write").
    :q - Quits vi.
    :q! - Quit vi without saving changes.
    :wq - Save the current file and quit.
    u - Undo the last edit or command.
    -r - Redo an undo.
    That is basically all you need to start off in vi.


    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/58679/showart_456004.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP