登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

windfly's sky

the sky I can fly like the wind

 
 
 

日志

 
 

vim的教程,各章小结  

2011-11-10 22:38:33|  分类: linux learn |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
学习vim 的入门就是先学习自带的教程,方法是输入$vimtutor,查看。
学习完毕之后,有些命令可能记不清楚了,需要查找,但是如果重新打开学习的话又费较多的时间。好在imtutor在每章都有小结,所以在此把各章小结粘下来,可以很快的帮助自己查找命令。

      第一讲小结


  1. 光标在屏幕文本中的移动既可以用箭头键,也可以使用 hjkl 字母键。
h (左移) j (下行)       k (上行)    l (右移)

  2. 欲进入vim编辑器(从命令行提示符),请输入∶vim 文件名 <回车>

  3. 欲退出vim编辑器,请输入以下命令放弃所有修改∶

<ESC>   :q! <回车>

     或者输入以下命令保存所有修改∶

<ESC>   :wq <回车>

  4. 在正常模式下删除光标所在位置的字符,请按∶ x

  5. 在正常模式下要在光标所在位置开始插入文本,请按∶

i     输入必要文本 <ESC>

特别提示∶按下 <ESC> 键会带您回到正常模式或者取消一个不期望或者部分完成
的命令。

好了,第一讲到此结束。下面接下来继续第二讲的内容。


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      第二讲小结


  1. 欲从当前光标删除至单字/单词末尾,请输入∶dw

  2. 欲从当前光标删除至当前行末尾,请输入∶d$

  3. 欲删除整行,请输入∶dd

  4. 在正常模式下一个命令的格式是∶

       [number]   command   object     或者     command [number]   object
     其意是∶
       number - 代表的是命令执行的次数
       command - 代表要做的事情,比如 d 代表删除
       object - 代表要操作的对象,比如 w 代表单字/单词,$ 代表到行末等等。
$ (to the end of line), etc.

  5. 欲撤消以前的操作,请输入∶u (小写的u)
     欲撤消在一行中所做的改动,请输入∶U (大写的U)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      第三讲小结


  1. 要重新置入已经删除的文本内容,请输入小写字母 p。该操作可以将已删除
     的文本内容置于光标之后。如果最后一次删除的是一个整行,那么该行将置
     于当前光标所在行的下一行。

  2. 要替换光标所在位置的字符,请输入小写的 r 和要替换掉原位置字符的新字
     符即可。

  3. 更改类命令允许您改变指定的对象,从当前光标所在位置直到对象的末尾。
     比如输入 cw 可以替换当前光标到单词的末尾的内容;输入 c$ 可以替换当
     前光标到行末的内容。

  4. 更改类命令的格式是∶

[number]   c object      或者 c   [number]   object

下面我们继续学习下一讲。


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      第四讲小结


  1. Ctrl-g 用于显示当前光标所在位置和文件状态信息。Shift-G 用于将光标跳
     转至文件最后一行。先敲入一个行号然后按 Shift-G 则是将光标移动至该行
     号代表的行。

  2. 输入 / 然后紧随一个字符串是则是在当前所编辑的文档中向后查找该字符串。
     输入问号 ? 然后紧随一个字符串是则是在当前所编辑的文档中向前查找该字
     符串。完成一次查找之后按 n 键则是重复上一次的命令,可在同一方向上查
     找下一个字符串所在;或者按 Shift-N 向相反方向查找下该字符串所在。

  3. 如果光标当前位置是括号(、)、[、]、{、},按 % 可以将光标移动到配对的
     括号上。

  4. 在一行内替换头一个字符串 old 为新的字符串 new,请输入  :s/old/new
     在一行内替换所有的字符串 old 为新的字符串 new,请输入  :s/old/new/g
     在两行内替换所有的字符串 old 为新的字符串 new,请输入  :#,#s/old/new/g
     在文件内替换所有的字符串 old 为新的字符串 new,请输入  :%s/old/new/g
     进行全文替换时询问用户确认每个替换需添加 c 选项,请输入 :%s/old/new/gc


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      第五讲小结


  1. :!command 用于执行一个外部命令 command。

     请看一些实际例子∶
 :!dir  -  用于显示当前目录的内容。
 :!rm FILENAME  - 用于删除名为 FILENAME 的文件。

  2. :w FILENAME  可将当前 VIM 中正在编辑的文件保存到名为 FILENAME 的文
     件中。

  3. :#,#w FILENAME 可将当前编辑文件第 # 行至第 # 行的内容保存到文件
     FILENAME 中。

  4. :r FILENAME 可提取磁盘文件 FILENAME 并将其插入到当前文件的光标位置
     后面。


      第六讲小结


  1. 输入小写的 o 可以在光标下方打开新的一行并将光标置于新开的行首,进入
     插入模式。
     输入大写的 O 可以在光标上方打开新的一行并将光标置于新开的行首,进入
     插入模式。

  2. 输入小写的 a 可以在光标所在位置之后插入文本。
     输入大写的 A 可以在光标所在行的行末之后插入文本。

  3. 输入大写的 R 将进入替换模式,直至按 <ESC> 键退出替换模式而进入正常
     模式。

  4. 输入 :set xxx 可以设置 xxx 选项。



      第七讲∶在线帮助命令

     ** 使用在线帮助系统 **

  Vim 拥有一个细致全面的在线帮助系统。要启动该帮助系统,请选择如下三种方
  法之一∶
- 按下 <HELP> 键 (如果键盘上有的话)
- 按下 <F1> 键 (如果键盘上有的话)
- 输入 :help <回车>

  输入 :q <回车> 可以关闭帮助窗口。

  提供一个正确的参数给":help"命令,您可以找到关于该主题的帮助。请试验以
  下参数(可别忘了按回车键哦。:)∶

 :help w <回车>
 :help c_<T <回车>
 :help insert-index <回车>
 :help user-manual <回车>




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      第八讲∶创建一个启动脚本

 ** 启用vim的功能 **

  Vim的功能特性要比vi多得多,但大部分功能都没有缺省激活。为了启动更多的
  功能,您得创建一个vimrc文件。

  1. 开始编辑vimrc文件,这取决于您所使用的操作系统∶

     :edit ~/.vimrc 这是Unix系统所使用的命令
     :edit $VIM/_vimrc 这是Windows系统所使用的命令

  2. 接着导入vimrc范例文件∶

     :read $VIMRUNTIME/vimrc_example.vim

  3. 保存文件,命令为∶

     :write

  在下次您启动vim的时候,编辑器就会有了语法高亮的功能。您可以继续把您喜
  欢的其它功能设置添加到这个vimrc文件中。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  vim 教程到此结束。本教程只是为了简明地介绍一下vim编辑器,但已足以让您
  很容易学会使用本编辑器了。毋庸质疑,vim还有很多很多的命令,本教程所介
  绍的还差得远著呢。所以您要精通的话,还望继续努力哦。下一步您可以阅读
  vim手册,使用的命令是∶
:help user-manual
////////////////////////////////////////////////////////////////////////////////
另外,英文版的多几个命令,例如v,y等,所以在此把英文版的小结也贴出来

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Lesson 1 SUMMARY


  1. The cursor is moved using either the arrow keys or the hjkl keys.
h (left) j (down)       k (up)    l (right)

  2. To start Vim from the shell prompt type:  vim FILENAME <ENTER>

  3. To exit Vim type:   <ESC>   :q! <ENTER>  to trash all changes.
    OR type:   <ESC>   :wq <ENTER>  to save the changes.

  4. To delete the character at the cursor type:  x

  5. To insert or append text type:
i   type inserted text   <ESC> insert before the cursor
A   type appended text   <ESC>         append after the line

NOTE: Pressing <ESC> will place you in Normal mode or will cancel
      an unwanted and partially completed command.

Now continue with Lesson 2.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      Lesson 2 SUMMARY


  1. To delete from the cursor up to the next word type:    dw
  2. To delete from the cursor to the end of a line type:    d$
  3. To delete a whole line type:    dd

  4. To repeat a motion prepend it with a number:   2w
  5. The format for a change command is:
               operator   [number]   motion
     where:
       operator - is what to do, such as  d  for delete
       [number] - is an optional count to repeat the motion
       motion   - moves over the text to operate on, such as  w (word),
 $ (to the end of line), etc.

  6. To move to the start of the line use a zero:  0

  7. To undo previous actions, type:       u  (lowercase u)
     To undo all the changes on a line, type:  U  (capital U)
     To undo the undo's, type:       CTRL-R

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      Lesson 3 SUMMARY


  1. To put back text that has just been deleted, type   p .  This puts the
     deleted text AFTER the cursor (if a line was deleted it will go on the
     line below the cursor).

  2. To replace the character under the cursor, type   r   and then the
     character you want to have there.

  3. The change operator allows you to change from the cursor to where the
     motion takes you.  eg. Type  ce  to change from the cursor to the end of
     the word,  c$  to change to the end of a line.

  4. The format for change is:

c   [number]   motion

Now go on to the next lesson.



      Lesson 4 SUMMARY


  1. CTRL-G  displays your location in the file and the file status.
             G  moves to the end of the file.
     number  G  moves to that line number.
            gg  moves to the first line.

  2. Typing  / followed by a phrase searches FORWARD for the phrase.
     Typing  ? followed by a phrase searches BACKWARD for the phrase.
     After a search type  n  to find the next occurrence in the same direction
     or  N  to search in the opposite direction.
     CTRL-O takes you back to older positions, CTRL-I to newer positions.

  3. Typing  % while the cursor is on a (,),[,],{, or } goes to its match.

  4. To substitute new for the first old in a line type    :s/old/new
     To substitute new for all 'old's on a line type   :s/old/new/g
     To substitute phrases between two line #'s type   :#,#s/old/new/g
     To substitute all occurrences in the file type   :%s/old/new/g
     To ask for confirmation each time add 'c'   :%s/old/new/gc

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      Lesson 5 SUMMARY


  1.  :!command  executes an external command.

      Some useful examples are:
(MS-DOS)  (Unix)
 :!dir   :!ls   -  shows a directory listing.
 :!del FILENAME   :!rm FILENAME   -  removes file FILENAME.

  2.  :w FILENAME  writes the current Vim file to disk with name FILENAME.

  3.  v  motion  :w FILENAME  saves the Visually selected lines in file
      FILENAME.

  4.  :r FILENAME  retrieves disk file FILENAME and puts it below the
      cursor position.

  5.  :r !dir  reads the output of the dir command and puts it below the
      cursor position.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      Lesson 6 SUMMARY

  1. Type  o  to open a line BELOW the cursor and start Insert mode.
     Type  O  to open a line ABOVE the cursor.

  2. Type  a  to insert text AFTER the cursor.
     Type  A  to insert text after the end of the line.

  3. The  e  command moves to the end of a word.

  4. Start Visual mode with  v  and move the cursor 
   The  y  operator yanks (copies) text,  p  puts (pastes) it.

  5. Typing a capital  R  enters Replace mode until  <ESC>  is pressed.

  6. Typing ":set xxx" sets the option "xxx".  Some options are:
  'ic' 'ignorecase' ignore upper/lower case when searching
'is' 'incsearch' show partial matches for a search phrase
'hls' 'hlsearch' highlight all matching phrases
     You can either use the long or the short option name.

  7. Prepend "no" to switch an option off:   :set noic

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      Lesson 7 SUMMARY


  1. Type  :help  or press <F1> or <Help>  to open a help window.

  2. Type  :help cmd  to find help on  cmd .

  3. Type  CTRL-W CTRL-W  to jump to another window

  4. Type  :q  to close the help window

  5. Create a vimrc startup script to keep your preferred settings.

  6. When typing a  :  command, press CTRL-D to see possible completions.
     Press <TAB> to use one completion.




  评论这张
 
阅读(354)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018