- 论坛徽章:
- 0
|
Starting and Ending VI
Starting VI
vi filename
Edits filename
vi -r filename
Edits last save version of filename after a crash
vi + n filename
Edits filename and places curser at line n
vi + filename
Edits filename and places curser on last line
vi +/string filename
Edits filename and places curser on first occurance of string
vi filename file2 ...
Edits filename, then edits file2 ... After the save, use :n
注:
1.最常用的编辑
2.当vi程序出错时,文件出错时很有用
3.编辑文件直接定位到N行,可以配合:set nu查看文件行号
4.编辑文件直接定位到最后一行
5.编辑文件并把光标直接定位到与当前字符匹配的行,这样的组合看上去太炫了。
6.编辑多文件,在Basic part提到了切换文件时可以输入:e filename 或用:n ,:p
Status
:.=
Shows current line number
:=
Shows number of lines in file
Control-G
Shows filename, current line number, total lines in file, and % of file location
l
Displays tab (^l) backslash (\) backspace (^H) newline ($) bell (^G) formfeed (^L^) of current line
Ranges
:n,m
Range - Lines n-m
:.
Range - Current line
:$
Range - Last line
:'c
Range - Marker c
:%
Range - All lines in file
:g/pattern/
Range - All lines that contain pattern
Shell Functions
:! cmd
Executes shell command cmd; you can add these special characters to indicate:% name of current file# name of last file edited
!! cmd
Executes shell command cmd, places output in file starting at current line
:!!
Executes last shell command
:r! cmd
Reads and inserts output from cmd
:f file
Renames current file to file (实验没通过,不知道是不是因为OS的原因)
:w !cmd
Sends currently edited file to cmd as standard input and execute cmd
:cd dir
Changes current working directory to dir
:sh
Starts a sub-shell (CTRL-d returns to editor)
!}sort
Sorts from current position to end of paragraph and replaces text with sorted text
注:
:sh 和 :!cmd有异曲同工之妙,我更喜欢:sh ,给人一种干净的界面
!}sort 是用来文本内容排序的
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/26090/showart_309812.html |
|