`

vi commonly used commands

阅读更多
1.插入命令

命令    作用
a     在光标后附加文本
A     在本行行末附加文本
i     在光标前插入文本
I     在本行开始插入文本
o     在光标下插入新行
O     在光标上插入新行


2.定位命令

命令   作用
H    移至屏幕上端
h    方向左键 左移一个字符 
j    方向下键 下移一行 
M    移至屏幕中央
k    方向上键 下移一行 
L    移至屏幕下端
l    方向右键 右移一个字符 
$    移至行尾 
0    移至行首 


:set nu    设置行号
:set nonu  取消行号
gg          到第一行
G           到最后一行
nG          到第n行
:n          到第n行


3。删除命令

命令          作用
x           删除光标所在处字符
nx          删除光标所在处后n个字符
dd          删除光标所在行,ndd删除n行
dG          删除光标所在行到末尾的内容
D           删除从光标所在处到行尾
:n1,n2d     删除指定范围的行



4.复制与剪切命令

命令        作用
yy、Y       复制当前行
nyy、nY     复制当前行一下n行
dd          剪切当前行
ndd         剪切当前行一下n行
p、P        粘帖在当前光标所在行下或行上


5.替换和取消命令 

命令        作用
r        取代光标所在处字符
R        从光标所在处开始替换字符,按Esc结束
u        取消上一步操作


6.搜索和替换命令 

命令                 作用
/string            向前搜索指定字符串搜索时忽略大小写 :set ic
n                  搜索指定字符串的下一个出现位置
:%s/old/new/g      全文替换指定字符串
:n1,n2s/old/new/g  在一定范围内替换指定字符串


7.保存和退出命令 

命令                作用
:w                 保存修改
:w new_filename    另存为制定文件
:wq                保存修改并退出
ZZ                 快捷键保存修改并退出
:q!                不保存修改退出
:wq!               保存修改并退出(文件所有者可忽略文件的只读属性)


8.技巧 

导入命令执行结果 :r !命令
定义快捷键 :map 快捷键 触发命令
范例: 
     :map ^P I#<ESC>
     :map ^B 0x
连续行注释 
     :n1,n2s/^/#/g
     :n1,n2s/^#//g
     :n1,n2s/^/\/\//g
替换 :ab sammail samlee@lampbrother.net




















分享到:
评论

相关推荐

    UNIX.and.Shell.Programming.0198082169

    An overview of file management in Unix and commonly used Unix commands is then provided. Further, it delves into the detailed description of file system and compression techniques, processes and ...

    常用VI命令

    This summary provides an overview of commonly used VI commands, covering cursor movement, searching and replacing, deleting, copying, and pasting, editing modes, and last line mode. 光标移动 * h或...

    UNIX Shell Programming(OXFORD,2014)

    An overview of file management in Unix and commonly used Unix commands is then provided. Further, it delves into the detailed description of file system and compression techniques, processes and ...

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...

    Ubuntu The Complete Reference

    - **Common Shell Commands**: List of commonly used commands, their syntax, and examples of usage. - **Shell Scripting Basics**: Introduction to shell scripting, including variables, loops, ...

Global site tag (gtag.js) - Google Analytics