×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

给大家贴一点实质性的东西,以下是我以前总结出来在公司内部贴的经验文档,介绍VI操作的,基本足够了

本文发表在 rolia.net 枫下论坛Vi命令

1、Vi有3个状态:操作状态、编辑状态和命令行状态
2、^f 表示CTRL-f

1 操作状态下命令:
1.1 光标移动类命令
0 Move to beginning of current line
^ Move to the first character of current line
$ Move to end of current line
h Move left a cursor
H Move to beginning of current page
l Move right a cursor
L Move to end of current page
j Move down a cursor
k Move up a cursor
G Move to end of file
]] Ditto
[[ Move to beginning of file
w move to the beginning of next word
W move to the beginning of next word,ignore interpunction
b move to the beginning of Last word
B move to the beginning of Last word,ignore interpunction
^f PageDown
^b PageUp
^d 1/2 PageDown
^u 1/2 PageUp
{ Move to the last space line
} Move to the next space line
( Move to the last different line (space line <-> line with words)
) Move to the next different line (space line <-> line with words)
- Move to the beginning of last line
+ Move to the beginning of next line
M Move to center line of current page
% Goto the matched bracket ('(',')','[',']','{','}')
fx Move forword to 'x' in current line
Fx Move back to 'x' in current line

1.2 编辑命令:
x Delete current char
nx Delete n characters
dd Delete current line
ndd Delete n lines
dG Delete to end of file
D Delete to end of current line
d$ Ditto
d0 From beginning delete to current cursor
d^ From first character delete to current cursor
dw Delete a word
dW Delete a word,ignore interpunction
(All delete command will save the what deleted into default buffer)
yy Copy current line
xyy Copy x lines
y$ Copy to end of line
y0 From beginning of current line copy to cursor
y^ From first charcter of current line copy to cursor
yw Copy a word
yW Copy a word,ignore interpunction
(All copy command copy to default buffer)
p paste after current cursor or current line
P paste before current cursor or current line
J Link following line to current line
rx use 'x' to replace current char
>> Move current line right a table key
<< Move current line left a table key
>% Move the lines between current bracket and the matched one right a table key
<% Move the lines between current bracket and the matched one left a table key
u undo last modify
U undo all modify of current line
~ Reverse the case of current character

1.3 状态迁移类命令
The following key will transfer vi state to edit mode
i Insert before cursor
I Insert before current line
a Insert after cursor
A Insert after current line
o Make a new line after current line
O Make a new line Before current line
s Into insert mode to replace current character
S Delete current line and Into insert mode
cc Ditto
cw Into insert mode to replace current word
C Into Insert mode to replace current line
c$ Ditto
c0 Into insert mode to replace beginning of line to current character
c^ Into insert mode to replace first character of line to current character
R Into modify mode

: Into command state,begin to get some command
/ Into command state,get search command
? Into command state,get search command

1.4 其他命令:
n Continue last search
N Continue last search in the reverse way
. re-do last command
^g Show brief of file in command line
^l refresh screen
"a Register a named buffer with name 'a'; The following command will execute with certain buffer

2 编辑状态下命令:
x Insert character 'x' to current file
ESC Back to control state
^c Back to control state
^h backspace
^j enter
^w Delete the fore-words


3 命令行状态命令:
r file Readin file and insert after current line
r !command Readin the output of shell command "command" and insert after current line
nr file Readin file and insert after the No.n line
!command Execute the shell command "command" and return
sh Transfer into shell command state, can use "exit" to return
w Save current file
wq Save and quit vi
x Ditto
q Quit
q! Quit ignore the modified of current file
e file Edit file
e! Ignore the modified of current file and reload this for edit
n Begin to edit next file
map n command Declare 'n' as a macro of command
unmap n Cancel the declare of macro 'n'
set env Set environ
set all Get brief help of 'set'
/ Search forward
? Search backward
g Global
s Replace
l1,l2command Excute command from line l1 to line l2


4 一些命令的详细介绍和应用举例

4.1 命名缓冲区的应用:
"q10dd Delete 10 lines and save them into buffer 'q'
"qp Paste from buffer 'q'
You can use named buffer to save something you usually used.

4.2 搜索的应用
/abcd Search "abcd" and skip to the next "abcd"
/[aA]bcd Search "abcd" or "Abcd" and skip to the next matched
/[aA][0-9].cd Search "anxcd" or "Axcd" and skip to the next matched , Here, n is a digital and x is any character

4.3 搜索替换的组合应用
base formate : /templet1/s/templet2/templet3
Search the matched line with templet1 and replace the templet2 with templet3
/abcd/s//dcba Search "abcd" and replace the first matched with "dcba", without give the templet2, default is templet1
g/abcd/s//dcba Search "abcd" and replace the first matched in every line with "dcba"
g/abcd/s//dcba/g Search "abcd" and replace all matched in file with "dcba"
g/abcd/s/123/321/g Replace all "123" with "321" in those line with "abcd"
10,30/abcd/s//dcba/g Replace all "123" with "321" between lines 10 to 30
g/\(abcd\)\(efg\)/s//\2---\1/g Replace all "abcdefg" wirh "efg---abcd"
说明:'/'为转义符,模板一中用括号将"abcdefg"分为两个子串"abcd"和"efg",缺省就是串1和串2,在替换模板中,用'/'分别引用串2和串1,中间加上了"---",达到以上目的

4.4 宏的应用
map ` /[{}]^Mi^M^[a^M^[ Search '{' or '}' and let it to occupy a single line. the command is :
/[{}]^M Search '{' or '}', follow an Enter (In command line use ctrl-v + Enter to input Enter key, ctrl-v is a Transfer key)
i^M^[ Insert Enter before '{' or '}', follow an Escape. (ctrl-v + Esc)
a^M^[ Insert Enter after '{' or '}', follow an Escape. (ctrl-v + Esc)

最常用set命令
set nu Show line number
set nonu Unshow line number
set tab=n Set table width n spaces
set ai Set autoindent
set noai Cancel autoindent
set all Get brief help of set更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT杂谈 / 各位DX,想请问在多伦多哪里学UNIX的比较好。另外,也还拿不定主意是直接学SUN公司的SOLARIS好呢,还是学其他的UNIX。从广告上看,好多都只写UNIX,也不知道是不是就是指SUN的。多谢了
    • 我也想知道。
    • up up!!!
    • Best way to study unix is at home, install solaris in your pc.
    • 那里学我不清楚,不过UNIX这个东东实在是高,是需要大量的开发和经验的,我个人工作了六年,称自己是专家,心里还扑腾乱跳。要学的化,其实无所谓学那种UNIX,绝对大同小异,个人建议你装一个Linux。
      • 同意你的看法,其实操作Unix 不难,难的是写Program
        • 操作不难吗?你敢说你能熟练合理地使用80%的unix命令吗?
          • linux和unix一样么?有什么具体的差别?
            • Linux是在Xenix(一种可以运行在386平台上的简化版免费UNIX)上改进来的,也是UNIX的一种。Linux和Solaris的差别并不比AIX或HP-UX和Solaris的差别大。
              • Ugh, no. Linux was written from scratch and has no relationship with xenix. The closest resemblance might be minix written by Andrew T.
            • 准确地说,UNIX只是一类操作系统的统称,是一个标准。事实上,任何UNIX系统都不能以UNIX注册。现有常用的UNIX有Solaris(Sun), AIX(IBM), HP-UX(HP), SCO-UNIX(SCO)等传统的商业UNIX和Linux,BSD等免费UNIX。
              • 高手!
          • 加上每个命令的各种选项. 能熟练使用30% 的阿拉已经佩服得五体投地了. Linux更不得了, UNIX上的什么"垃圾"都有.
            • 就是, 象vi就需要一整本书才能完全讲清楚.
              • 给大家贴一点实质性的东西,以下是我以前总结出来在公司内部贴的经验文档,介绍VI操作的,基本足够了
                本文发表在 rolia.net 枫下论坛Vi命令

                1、Vi有3个状态:操作状态、编辑状态和命令行状态
                2、^f 表示CTRL-f

                1 操作状态下命令:
                1.1 光标移动类命令
                0 Move to beginning of current line
                ^ Move to the first character of current line
                $ Move to end of current line
                h Move left a cursor
                H Move to beginning of current page
                l Move right a cursor
                L Move to end of current page
                j Move down a cursor
                k Move up a cursor
                G Move to end of file
                ]] Ditto
                [[ Move to beginning of file
                w move to the beginning of next word
                W move to the beginning of next word,ignore interpunction
                b move to the beginning of Last word
                B move to the beginning of Last word,ignore interpunction
                ^f PageDown
                ^b PageUp
                ^d 1/2 PageDown
                ^u 1/2 PageUp
                { Move to the last space line
                } Move to the next space line
                ( Move to the last different line (space line <-> line with words)
                ) Move to the next different line (space line <-> line with words)
                - Move to the beginning of last line
                + Move to the beginning of next line
                M Move to center line of current page
                % Goto the matched bracket ('(',')','[',']','{','}')
                fx Move forword to 'x' in current line
                Fx Move back to 'x' in current line

                1.2 编辑命令:
                x Delete current char
                nx Delete n characters
                dd Delete current line
                ndd Delete n lines
                dG Delete to end of file
                D Delete to end of current line
                d$ Ditto
                d0 From beginning delete to current cursor
                d^ From first character delete to current cursor
                dw Delete a word
                dW Delete a word,ignore interpunction
                (All delete command will save the what deleted into default buffer)
                yy Copy current line
                xyy Copy x lines
                y$ Copy to end of line
                y0 From beginning of current line copy to cursor
                y^ From first charcter of current line copy to cursor
                yw Copy a word
                yW Copy a word,ignore interpunction
                (All copy command copy to default buffer)
                p paste after current cursor or current line
                P paste before current cursor or current line
                J Link following line to current line
                rx use 'x' to replace current char
                >> Move current line right a table key
                << Move current line left a table key
                >% Move the lines between current bracket and the matched one right a table key
                <% Move the lines between current bracket and the matched one left a table key
                u undo last modify
                U undo all modify of current line
                ~ Reverse the case of current character

                1.3 状态迁移类命令
                The following key will transfer vi state to edit mode
                i Insert before cursor
                I Insert before current line
                a Insert after cursor
                A Insert after current line
                o Make a new line after current line
                O Make a new line Before current line
                s Into insert mode to replace current character
                S Delete current line and Into insert mode
                cc Ditto
                cw Into insert mode to replace current word
                C Into Insert mode to replace current line
                c$ Ditto
                c0 Into insert mode to replace beginning of line to current character
                c^ Into insert mode to replace first character of line to current character
                R Into modify mode

                : Into command state,begin to get some command
                / Into command state,get search command
                ? Into command state,get search command

                1.4 其他命令:
                n Continue last search
                N Continue last search in the reverse way
                . re-do last command
                ^g Show brief of file in command line
                ^l refresh screen
                "a Register a named buffer with name 'a'; The following command will execute with certain buffer

                2 编辑状态下命令:
                x Insert character 'x' to current file
                ESC Back to control state
                ^c Back to control state
                ^h backspace
                ^j enter
                ^w Delete the fore-words


                3 命令行状态命令:
                r file Readin file and insert after current line
                r !command Readin the output of shell command "command" and insert after current line
                nr file Readin file and insert after the No.n line
                !command Execute the shell command "command" and return
                sh Transfer into shell command state, can use "exit" to return
                w Save current file
                wq Save and quit vi
                x Ditto
                q Quit
                q! Quit ignore the modified of current file
                e file Edit file
                e! Ignore the modified of current file and reload this for edit
                n Begin to edit next file
                map n command Declare 'n' as a macro of command
                unmap n Cancel the declare of macro 'n'
                set env Set environ
                set all Get brief help of 'set'
                / Search forward
                ? Search backward
                g Global
                s Replace
                l1,l2command Excute command from line l1 to line l2


                4 一些命令的详细介绍和应用举例

                4.1 命名缓冲区的应用:
                "q10dd Delete 10 lines and save them into buffer 'q'
                "qp Paste from buffer 'q'
                You can use named buffer to save something you usually used.

                4.2 搜索的应用
                /abcd Search "abcd" and skip to the next "abcd"
                /[aA]bcd Search "abcd" or "Abcd" and skip to the next matched
                /[aA][0-9].cd Search "anxcd" or "Axcd" and skip to the next matched , Here, n is a digital and x is any character

                4.3 搜索替换的组合应用
                base formate : /templet1/s/templet2/templet3
                Search the matched line with templet1 and replace the templet2 with templet3
                /abcd/s//dcba Search "abcd" and replace the first matched with "dcba", without give the templet2, default is templet1
                g/abcd/s//dcba Search "abcd" and replace the first matched in every line with "dcba"
                g/abcd/s//dcba/g Search "abcd" and replace all matched in file with "dcba"
                g/abcd/s/123/321/g Replace all "123" with "321" in those line with "abcd"
                10,30/abcd/s//dcba/g Replace all "123" with "321" between lines 10 to 30
                g/\(abcd\)\(efg\)/s//\2---\1/g Replace all "abcdefg" wirh "efg---abcd"
                说明:'/'为转义符,模板一中用括号将"abcdefg"分为两个子串"abcd"和"efg",缺省就是串1和串2,在替换模板中,用'/'分别引用串2和串1,中间加上了"---",达到以上目的

                4.4 宏的应用
                map ` /[{}]^Mi^M^[a^M^[ Search '{' or '}' and let it to occupy a single line. the command is :
                /[{}]^M Search '{' or '}', follow an Enter (In command line use ctrl-v + Enter to input Enter key, ctrl-v is a Transfer key)
                i^M^[ Insert Enter before '{' or '}', follow an Escape. (ctrl-v + Esc)
                a^M^[ Insert Enter after '{' or '}', follow an Escape. (ctrl-v + Esc)

                最常用set命令
                set nu Show line number
                set nonu Unshow line number
                set tab=n Set table width n spaces
                set ai Set autoindent
                set noai Cancel autoindent
                set all Get brief help of set更多精彩文章及讨论,请光临枫下论坛 rolia.net
                • 谢谢,打印了。
          • 80%? No problem. Try me.
            • List out the installed hardware; can you gaive the commands in Hp-UX; Sco-UNIX, Linux and Solaris?
              • I only know in HP-UX is ioscan. Last time, I have an interview, they asked the same question for SCO-UNIX, ioscan was not the righr answer.
                • The command in AIX is lsdev , and what is the command in Sco-UNIX?
      • Knowing 2% of UNIX commands is enough. The point is you need to know where to find the commands and the references. Understanding UNIX structure is more important than remembering all junk commands.
        • Yeah, you r right! if you know these commands: cd, ls, login, exit and man, that's enought for you to begin to play UNIX, of coz, you should know some simple operation for vi.
          • 多谢东方大哥的热心指导.其实我觉得,如果只是单纯学一门操作系统,恐怕也不会太难.可计算机这东西,实践实在太重要了,不知道你在这方面有什么好的建议呢?先谢过了!
    • 有知道找工作带CO-OP的培训班吗?
      • 有个针对新移民的NOW PROGRAM,一个月找工技能培训,一个月CO-OP,Tel:(416) 393-0350. 每班20人,5周一班,赶快报名!
        • really . it is very good for new comers.
        • 我也知道这件事儿.我是在10月份去那里的,可是实在太多人在排队,只有等到1月份才有机会,而且还不一定能参加的了,可能还有什么考试吧.到时去看看再说.
          • 我前天去了这个地方,一个黑姐姐要我三月再去面谈,以决定要不要我。
    • I want to know too. Hope more DX will post their suggestions
    • ^