Chinaunix首页 | 论坛 | 博客
  • 博客访问: 418635
  • 博文数量: 114
  • 博客积分: 3361
  • 博客等级: 中校
  • 技术积分: 1060
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-18 13:14
文章分类

全部博文(114)

文章存档

2012年(1)

2011年(84)

2010年(29)

分类: LINUX

2010-05-18 13:51:29

开始学习Linux,先从vi开始~

刚刚接触vi,便发现这个才是我想要的编辑工具,经过几天的学习,现在已经发现这个工具的强大之处了,慢慢的总结了一些东西,觉得很有用.

"""""""""""""""" 进入离开 最最基本的操作
这里都是最基本的操作,包括移动,打开关闭,学会了移动,才真正进入了vi的大门
Q to Ex mode,
visual eixt Ex mode

:e a.txt 打开文档 edit
:e! 重新载入文档
:w 保存文档 write
:q 关闭文档 quit
:q! 
:wq

:close 关闭当前文档

:ver 显示当前 vim 的版本 version

h backspace
j + Enter
k -
l space
ctrl-f 下一页 forward
ctrl-b 上一页 backward

0  zero 行首,含空白字符
^ 第一个非空白字符
$ 行尾
G 文档未
gg 文档首(only vim)
1G 文档首

w word
W word ignore interpunction
e end of word
E end of word ignore interpunction
b back a word
B back a word ignore interpunction

H high
M middle
L low

n| go to charactor n
:n goto line n  eg:15   :22

) next sentence
( previous sentence   sentence is distinquished by  . ! ?

} next paragraph
{ previous paragraph    paragraph is distinquished by white line

& 匹配 (){}[]用

J join 连接下一行
gJ 中文链接下一行 无空格

"""""""""""""""" enter insert mode
i insert befor current charactor
a insert after current charactor
o insert at a new line under current line
I insert at the begin of the current line
A insert end the current line usefull
O insert at o new line above current line
 
"""""""""""""""" delete command
x 删除当前字符
X 删除当前的前一个字符
dd delete line
dw delete a word
dG delete to end of the file
d1G delete to begin of the file
dgg delete to begin of the file (only for vim)
D delete to end of line
d$
d0 delete to begin of line
d^

""""""""""""""" replace and revert
r 取代游标所在处字符
R 进入 replace mode
cc replace line
S replace line
cw replace a word
~ 互换大小写
C replace to end of line
c$
c0 replace to begin of line
c^
s 替换一个字符为你输入的内容,是插入式的取代
u undo
U 恢复到游标没有离开文本之前
ctrl-r redo

"""""""""""""""  简单重排功能
其实这个功能我觉得用不到的
>> Right shift line
<< left shift line
:set shiftwidth=4
:set sw=4
:center center current line
:ce
:right right current line
:re
:left left current line
:le
:set textwidth
:set tw

gqap 本段重排
gqip
gqq 本行重排
gqQ 游标所在段落重排至文件尾

gq3q 重排3行
gq2ap 重排两端
gq5j 重排5行
gq}

""""""""""""""" yank
yank在这里就是 copy 了,可不是美国佬
yy copy current line
yyp copy and insert line
Y
2yy copy two line
y2y
y^ copy to begin of line
y0
y$ copy to end of line, include current charactor
yw copy a word
y2w copy two word
yG copy to end of file
y1G copy to begin to file

p put after cursor
P put befor cursor

"ayy 将本行复制到 a 的缓冲区
"Ayy 将本行 append 到 a 的缓冲区里面
:ap 将 a 缓冲区的内容 put 出来

:registers 查看缓冲区
:reg

"""""""""""""""  牛
这个命令,一个字:牛
. 重复之前的命令
p dd dw r cw ...

Shift-insert Windows下插入剪贴板里的内容
还有鼠标中键也可以啊

""""""""""""""" Search
查找时我在修改编辑时候用的最多的指令了
/ serach ahead
? search back
n search next
N search befor
* 查找游标处所在单词 n,N仍然可用
# 向后查找有标出所在单词 n,N仍然可用
g* 部分匹配查找单词 n,N仍然可用
g# 向后部分匹配查找单词 n,N仍然可用

""""""""""""""" substitute
这个功能还不怎么会用,一直是手工替换的,因为要替换的东西都不多
:[range]s/pattern/string/[cegi]
:1,5s/hello/h/cgi
% 1,$ 从第一行到最后一行

""""""""""""""" bookmark
书签功能,我觉得编辑器必备的东东,以前用UltraEdit时,那个编辑器也有这个功能,不过用过Vim的就发现两者不是一个数量级的了
mx x 代表26个英文字符
`x backward quote tab上那个
'x forward quote enter隔壁那个

'A 回到所有标记过 mA 的档案
'1 回到前一次编辑的档案的最后位置

:marks 显示所有的书签

""""""""""""""" 开档案
vim a.txt
vim 15.txt
vim /hello 15.txt

""""""""""""""" 多档案编辑 argument list & buffer list
现在多档案编辑还是比较习惯 :tabnew 多个tab页进行编辑
:n next file
:2n next 2 file
:N previous file  只用于 argument list 的形式
:e a.txt
:e# 编辑上一个档案
ctrl-^ 编辑上一个档案
# 代表前一次编辑的档案
:files list all buffered files # 上次编辑的 % 正在编辑的 + 修改过
:buffersA
:ls
:bn buffer next
:bp buffer previous
:bl buffer last
:b档案名或者编号
:bd 删除 buffer
:bdelete

:f 显示当前文档名,是否修改,游标位置
ctrl-g
:f 档名 改变编辑中的档案名
:r 档名 read a file 在游标处插入一个文档
:33 r 档名 将档案插入到35行之后

gf vim 特殊用法 打开游标处所在单词为名的档案

""""""""""""""" 离开
:q
:q!
:wq
:x 存档离开,如果没有修改则不会存档
ZZ 和 :x 完全一样
:w 档案名 另存为
:qa

:set noswf 关闭 swf 交换文件

:recover 档名 恢复
vim -r 档名

""""""""""""""" 
阅读(890) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~