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

My Unix World

不要迷恋Unix,Unix只是计算世界很小的一部分!

 
 
 

日志

 
 

vimtutor 笔记整理  

2009-02-16 21:30:15|  分类: utility-vim |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Emacs 虽然强大并且优雅,但比较适合作为个人操作平台,单纯写程序,Vim足够了。这是从vimtutor中整理出来的,作为备忘录。

vim源于vi,是Unix中的另一款编辑器,在所有的编辑器中有重要的地位,有句流传很广的话“程序员有三种,第一种是使用vi的,第二种是使用Emacs的,第三种使用其他的编辑器”,足见vi和Emacs的地位。最常见的编辑器是windows中的记事本,这个为所有的人知晓,但其实从功能上看,很一般般。

vimtutor 是vim的入门帮助文档,都是一些最基本的操作。

一,文件操作

:q!                                               quit and not save

:wq                                             save and quit.

:e FileName                            edit the specific file.

:w filename                            save as filename

:r Filename                              read a file and insert it to current place.

:r !ls                                            can read the input of ls command and insert them into current place.

二,光标移动

h j k l                                           move left up down right

0                                                   move to the begin of a line.

$                                                   move to the end of a line.

e                                                  move to the end of a word.

w                                               move to the begin of second word

2e, 2w                                        move to the end/begain of the second word.

C^g                                             show the current line number of the file.

gg                                                move to the start of the file

G                                                  move to the bottom of the file

number G                                go to the specific line

%                                                 move to the matching (, ], or }

三,进入插入模式的方式

i                                                    insert to current place.

a                                                   insert to next character.

A                                                  insert to the end of this line.

o                                                  open a new line bellow,

O                                                  open a new line above.

四,文本操作

x                                                   delete unwanted character, and then into the text editing mode.

c[number]w/e/$                   cut current several word or line form current place

d[number]w/e/$/d             to delete. dw word, de, to the end of the current word, d$ to the end of the line, dd, the whole line. Numbers can be used to delete several, d2w,d2d

r                                                   replace the current character with typed key. such as r6 will replace current character by 6.

R                                                  replace more than one charactors.

u                                                  undo previous action, U, undo all the changes on a line, C^R, to undo the undo's.

v                                                   select part of the files

y                                                   copy the selected text by v

p                                                  paste the cut or copyed text to current place.

:w filename                             write the selected text to a file

五,查找和替换

1, :/ :? search forward or backward,

    n, N, when searching, n search again, N search again but the opposite derection

    C^o, go back before n used,

    C^i, go foreward

2, :s/old/new/g , to replace old to new, g means all in that line

    :#,#s/old/new/g, #,# are 2 line number.

    :%s/old/new/g , to change every occurrence in the whole file.

    :%s/old/new/gc, to find every occurrence in the whole file, with a prompt whether to substitute or not.

六,设置和帮助

1, :! execute an external command.

    :set ic ,means ignore case when searching, which is the same as :/keyword\c.

    :set noic, disable ignoring case.

    :set hls is, set the hlsearch and incsearch options.

2, :help open the help window,

    :help w

    :help c_CTRL-D

    :help insert-index

    :help user-manual

3, make sure vim is not in compatible mode :set nocp

    type the beginning of the command, such as :e

    C^d will shows all the vim command start by e, and <tab> will complete the name.

4, vim has many more features than vi, but they are disabled by default. These featrues are specified by the ~/.vimrc. There is an example file $VIMRUNTIME/vimrc_example.vim

  评论这张
 
阅读(277)| 评论(0)
推荐 转载

历史上的今天

评论

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

页脚

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