zendevelop

learn & share

Basic Edit in vim

在介绍了vim的三种模式之后,我开始介绍在vim中进行edit所使用到的基本命令。

Moving around

要进行code的编辑,找到进行编辑的位置是首先要做到的,首先介绍怎样将cursor做上下左右的移动,命令如下图所示:

在normal mode下, 
h(left), l(right), k(up), j(down)是移动cursor最采用的键,至于为什么要使用这几个看起来毫无关联的key,一句话: No explanation, just practice.

只有在不停的使用中,你才会发现最常用的这几个功能采用这样的按键是多么合理。

Insert

 

在上一节中已经讲过两种方法(i,a)可以进入到insert mode,为插入字符的方法,还有两种方法可以插入新的行:

i: insert a character before the character under the cursor.

a: append a character after the character under the cursor.

o: open a new line below the cursor.

O(uppercase): open a new line above the cursor.

Delete

Delete和insert有些类似,提供了删除单个字符和删除行的方法:

x: delete a character under the cursor.

dd: delete the line under the cursor.

xdd支持前面带一个数字前缀来表示删除的数量,使删除工作得到简化,如:

3x,5dd:表示删除从cusor所在位置往下的3个和5行。

有很多command都支持数字前缀,后面会陆续讲到。

Undo & redo

u: undo the last edit.

Ctrl + R: redo( reverse the preceding command ).

U(uppercase): undo the last edit line, but typing this command twice to cancel the preceding U.


Save & exit

:wq<Enter>, ZZ: write the file and exit.

:q!: quite and throw things away.

:e!: back to the last saved version.

上述就是在整个编辑过程中所要用到的基本的命令,有了这些命令,基本上就可以在vim中进行最基本的编辑操作,当然vim还提供了更多的命令来辅助整个编辑过程,后面会陆续讲到。

将上面讲到的内容用思维导图可以做以下描述:


希望增加思维导图来帮助记忆住这些常用的命令,能够很快将vim应用起来。

下一节主要介绍:help的用法,要学习好vim,经常要查找vim自带的帮助文件,而且本身vim的help就有一个简单的教程来帮助学习,我们要善于对这些资料进行发掘。

posted on 2009-09-16 00:11  zendevelop  阅读(321)  评论(0编辑  收藏  举报

导航