linux环境下vi命令编辑器详解(fedoraubuntu)
Linux下的vi编辑器的简单使用操作方法

Linux下的vi编辑器的简单使⽤操作⽅法vi编辑器的使⽤:vi编辑器有三种基本⼯作模式,分别是命令⾏模式、⽂本输⼊模式、末⾏模式。
1.命令⾏模式该模式是进⼊vi编辑器后的默认模式,任何时候,不管⽤户处于何种模式,按下esc键即可进⼊命令⾏模式。
在命令⾏模式下,可以输⼊vi命令来管理⾃⼰的⽂档。
此时在键盘上输⼊任何字符都被当作编辑命令,⽽不是输⼊字符。
输⼊的字符并不会在屏幕上显⽰,若是合法的vi命令,则会完成相应的动作,否则会响铃报警。
2.⽂本输⼊模式命令⾏模式下输⼊以下⼏个命令则会进⼊⽂本输⼊模式。
i: 插⼊命令,会将⽂本插⼊到光标所在位置之前I: 插⼊命令,会将⽂本插⼊到光标所在⾏的⾏⾸a: 追加⽂本命令,会将⽂本追加到光标当前位置之后A: 追加⽂本命令,会将⽂本追加到光标所在⾏的末尾o: 空⾏插⼊命令,将在光标所在⾏的下⾯插⼊⼀个空⾏,并将光标置于该⾏的⾏⾸O: 空⾏插⼊命令,将在光标所在⾏的上⾯插⼊⼀个空⾏,并将光标置于该⾏的⾏⾸c: 修改命令r: 取代命令s: 替换命令在该模式下,⽤户输⼊的任何字符都被当做⽂件内容保存起来,并显⽰在屏幕上。
3.末⾏模式命令⾏模式下,⽤户按下:键即可进⼊末⾏模式,此时vi会在显⽰窗⼝的最后⼀⾏显⽰⼀个:作为末⾏模式的说明符,等待⽤户输⼊命令。
多数⽂件管理命令都是在此模式下执⾏的。
末⾏命令执⾏完后,vi会⾃动回到命令⾏模式4.vi⽂本的删除命令:vi编辑器可以在编辑模式和命令⾏模式下删除⽂本。
命令⾏模式下,vi常⽤删除命令x 删除光标处的字符。
若在x之前加上⼀个数字n,则删除从光标所在位置开始向右的n个字符。
X 删除光标前⾯的字符。
若在X之前加上⼀个数字n,则删除从光标前⾯那个字符开始向左的n个字符。
dd 删除光标所在的整⾏。
前⾯加上数字n,则删除当前⾏以及其后的n-1⾏。
D 或 d$ 删除从光标所在处开始到⾏尾的内容。
d( 删除到上⼀句开始的所有字符d) 删除到下⼀句开始的所有字符d{ 删除到上⼀段开始的所有字符d} 删除到下⼀段开始的所有字符d0 删除从光标前⼀个字符开始到⾏⾸的内容dw 删除⼀个单词。
Linux系统中vi命令的详细解释

Linux系统中vi命令的详细解释在Linux系统中,vi编辑器是个功能强大的富文本编辑器,那么下面由店铺为大家整理了linux系统中vi命令的详细解释的相关知识,希望对大家有帮助!Linux系统中vi命令的详细解释vi命令vi命令是UNIX操作系统和类UNIX操作系统中最通用的全屏幕纯文本编辑器。
Linux中的vi编辑器叫vim,它是vi的增强版(vi Improved),与vi编辑器完全兼容,而且实现了很多增强功能。
vi编辑器支持编辑模式和命令模式,编辑模式下可以完成文本的编辑功能,命令模式下可以完成对文件的操作命令,要正确使用vi编辑器就必须熟练掌握着两种模式的切换。
默认情况下,打开vi编辑器后自动进入命令模式。
从编辑模式切换到命令模式使用“esc”键,从命令模式切换到编辑模式使用“A”、“a”、“O”、“o”、“I”、“i”键。
vi编辑器提供了丰富的内置命令,有些内置命令使用键盘组合键即可完成,有些内置命令则需要以冒号“:”开头输入。
常用内置命令如下:Ctrl+u:向文件首翻半屏;Ctrl+d:向文件尾翻半屏;Ctrl+f:向文件尾翻一屏;Ctrl+b:向文件首翻一屏;Esc:从编辑模式切换到命令模式;ZZ:命令模式下保存当前文件所做的修改后退出vi;:行号:光标跳转到指定行的行首;:$:光标跳转到最后一行的行首;x或X:删除一个字符,x删除光标后的,而X删除光标前的;D:删除从当前光标到光标所在行尾的全部字符;dd:删除光标行正行内容;ndd:删除当前行及其后n-1行;nyy:将当前行及其下n行的内容保存到寄存器?中,其中?为一个字母,n为一个数字;p:粘贴文本操作,用于将缓存区的内容粘贴到当前光标所在位置的下方;P:粘贴文本操作,用于将缓存区的内容粘贴到当前光标所在位置的上方;/字符串:文本查找操作,用于从当前光标所在位置开始向文件尾部查找指定字符串的内容,查找的字符串会被加亮显示;name:文本查找操作,用于从当前光标所在位置开始向文件头部查找指定字符串的内容,查找的字符串会被加亮显示;a,bs/F/T:替换文本操作,用于在第a行到第b行之间,将F字符串换成T字符串。
linux文件编辑vi的常见操作命令

linux文件编辑vi的常见操作命令vi是一款常用的文本编辑器,在Linux系统中被广泛使用。
下面将介绍vi的常见操作命令,帮助初学者快速掌握vi的基本使用。
1. 打开文件:使用vi命令加上要编辑的文件名,例如`vi filename`。
如果文件不存在,则会创建一个新文件。
2. 保存文件:在正常模式下,按下`:w`命令可以将文件保存。
如果文件是新创建的,需要指定文件名,例如`:w newfilename`。
3. 退出vi:在正常模式下,输入命令`:q`可以退出vi。
如果文件有未保存的修改,vi会提示保存或放弃修改。
如果想强制退出vi,可以使用命令`:q!`。
4. 插入文本:在正常模式下,按下`i`命令可以进入插入模式,在光标位置前插入文本。
按下`a`命令可以在光标位置后插入文本。
按下`o`命令可以在下一行插入新行并进入插入模式。
5. 删除文本:在正常模式下,按下`x`命令可以删除光标所在位置的字符。
按下`dd`命令可以删除整行。
按下`dw`命令可以删除一个词。
按下`d$`命令可以删除光标位置到行尾的内容。
6. 复制和粘贴文本:在正常模式下,按下`yy`命令可以复制整行。
按下`yw`命令可以复制一个词。
按下`p`命令可以粘贴复制的内容。
7. 撤销和重做:在正常模式下,按下`u`命令可以撤销上一步操作。
按下`Ctrl + r`命令可以重做被撤销的操作。
8. 查找和替换:在正常模式下,按下`/text`命令可以向下查找匹配的文本。
按下`?text`命令可以向上查找匹配的文本。
按下`:%s/old/new/g`命令可以替换全文中的old为new。
9. 移动光标:在正常模式下,按下`h`命令可以将光标向左移动一个字符。
按下`j`命令可以将光标向下移动一行。
按下`k`命令可以将光标向上移动一行。
按下`l`命令可以将光标向右移动一个字符。
按下`gg`命令可以将光标移动到文件开头。
按下`G`命令可以将光标移动到文件末尾。
ubuntu下vi编辑器使用方法

ubuntu下vi编辑器使用方法(zhuan)模式切换:一般模式切换输入模式(i/a/o)"i" insert - 在目前游标之处插入所要输入之文字"a" append - 在目前游标所在的下一行开始输入文字"o" open - 新增一行在游标的下,并从行首开始输人文字任何模式退回一般模式(Esc)以下命令均须退回到一般模式移动游标h、j、k、l:分别控制游标左、下、土、右移一格,也可以用方向键。
Ctrl+b : 往前一页Ctrl+f : 往后一页G : 移到文件最后w : 移到下个 word 的开头b : 跳至上个 wore 的开头删除x:删除所在后面一个字符#x:ex:5x 表删除 5 个字符dd:删除游标所在之行#dd:例,5dd 表删除自游标算起之 5 行更改cw:更改游标处之字到此一单字之字尾处c#w:例,c3w表更改 3 个字取代r:取代游标处之字符R:取代字符直到按 ESC 为止复制yw:拷贝游标处之字到字尾至缓冲区P:把缓冲区之资料贴上来yy:拷贝游标所在之行至缓冲区#yy:ex:5yy,拷贝游标所在之处以下 5 行至缓冲区复原u:undo,复原至上一动作跳至指定之行g:列出行号,及相关信息命令列下命令简介注意:使用前请先按 ESC 键确定在一般模式下按 ':' 或 '/' 或 '?' 叁键即可进入命令列模式列出行号:set nu寻找字串word ( 由首至尾寻找 ),按 n 可往下继续找word ( 由尾至首寻找 ),按 N 可往前继续找改命令可以用“/”代替跳行:100 - 可跳至第 100 行一般模式进入命令行模式(:):w filename ( 存入指定文件 ):wq ( 写入并离开 vi ):q! ( 强迫离开并放弃编辑的文件 ):n [ 文件 ] - 引入下一个文件:l,l2d - 删除自行l至行 l2 的文字:l,l2s/patternl/pattern2/g - 将行 l 至行 l2 的文字, patternl 的字串改为 pattern2 的字串,如无 g 则仅更换每一行所匹配的第一个字串,如有 g 则将每一个字串均做更换。
Ubuntuvi命令

Ubuntuvi命令最近在使⽤ubuntu,在linux下,要编辑⽂件或者其他的⽂本⽂件,哪那么⼀个ubuntu linux下的强⼤的⽂本编辑⼯具就不得不提了,那就是VI编辑器。
下⾯把VI常⽤到的命令⾏贴出来。
进⼊vi的命令vi filename :打开或新建⽂件,并将光标置于第⼀⾏⾸vi +n filename :打开⽂件,并将光标置于第n⾏⾸vi + filename :打开⽂件,并将光标置于最后⼀⾏⾸vi +/pattern filename:打开⽂件,并将光标置于第⼀个与pattern匹配的串处vi -r filename :在上次正⽤vi编辑时发⽣系统崩溃,恢复filenamevi filename….filename :打开多个⽂件,依次进⾏编辑移动光标类命令h :光标左移⼀个字符l :光标右移⼀个字符space:光标右移⼀个字符Backspace:光标左移⼀个字符k或Ctrl+p:光标上移⼀⾏j或Ctrl+n :光标下移⼀⾏Enter :光标下移⼀⾏w或W :光标右移⼀个字⾄字⾸b或B :光标左移⼀个字⾄字⾸e或E :光标右移⼀个字⾄字尾) :光标移⾄句尾( :光标移⾄句⾸}:光标移⾄段落开头{:光标移⾄段落结尾nG:光标移⾄第n⾏⾸n+:光标下移n⾏n-:光标上移n⾏n:光标移⾄第n⾏尾H:光标移⾄屏幕顶⾏M:光标移⾄屏幕中间⾏L:光标移⾄屏幕最后⾏0:(注意是数字零)光标移⾄当前⾏⾸:光标移⾄第n⾏尾H:光标移⾄屏幕顶⾏M:光标移⾄屏幕中间⾏L:光标移⾄屏幕最后⾏0:(注意是数字零)光标移⾄当前⾏⾸:光标移⾄当前⾏尾屏幕翻滚类命令Ctrl+u:向⽂件⾸翻半屏Ctrl+d:向⽂件尾翻半屏Ctrl+f:向⽂件尾翻⼀屏Ctrl+b;向⽂件⾸翻⼀屏nz:将第n⾏滚⾄屏幕顶部,不指定n时将当前⾏滚⾄屏幕顶部。
插⼊⽂本类命令i :在光标前I :在当前⾏⾸a:光标后A:在当前⾏尾o:在当前⾏之下新开⼀⾏O:在当前⾏之上新开⼀⾏r:替换当前字符R:替换当前字符及其后的字符,直⾄按ESC键s:从当前光标位置处开始,以输⼊的⽂本替代指定数⽬的字符S:删除指定数⽬的⾏,并以所输⼊⽂本代替之ncw或nCW:修改指定数⽬的字nCC:修改指定数⽬的⾏删除命令ndw或ndW:删除光标处开始及其后的n-1个字do:删⾄⾏⾸d$:删⾄⾏尾ndd:删除当前⾏及其后n-1⾏x或X:删除⼀个字符,x删除光标后的,⽽X删除光标前的Ctrl+u:删除输⼊⽅式下所输⼊的⽂本搜索及替换命令/pattern:从光标开始处向⽂件尾搜索patternpattern:从光标开始处向⽂件⾸搜索patternn:在同⼀⽅向重复上⼀次搜索命令N:在反⽅向上重复上⼀次搜索命令:s/p1/p2/g:将当前⾏中所有p1均⽤p2替代:n1,n2s/p1/p2/g:将第n1⾄n2⾏中所有p1均⽤p2替代:g/p1/s//p2/g:将⽂件中所有p1均⽤p2替换选项设置all:列出所有选项设置情况term:设置终端类型ignorance:在搜索中忽略⼤⼩写list:显⽰制表位(Ctrl+I)和⾏尾标志($)number:显⽰⾏号report:显⽰由⾯向⾏的命令修改过的数⽬terse:显⽰简短的警告信息warn:在转到别的⽂件时若没保存当前⽂件则显⽰NO write信息nomagic:允许在搜索模式中,使⽤前⾯不带“\”的特殊字符nowrapscan:禁⽌vi在搜索到达⽂件两端时,⼜从另⼀端开始mesg:允许vi显⽰其他⽤户⽤write写到⾃⼰终端上的信息最后⾏⽅式命令:n1,n2 co n3:将n1⾏到n2⾏之间的内容拷贝到第n3⾏下:n1,n2 m n3:将n1⾏到n2⾏之间的内容移⾄到第n3⾏下:n1,n2 d :将n1⾏到n2⾏之间的内容删除:w :保存当前⽂件:e filename:打开⽂件filename进⾏编辑:x:保存当前⽂件并退出:q:退出vi:q!:不保存⽂件并退出vi:!command:执⾏shell命令command:n1,n2 w!command:将⽂件中n1⾏⾄n2⾏的内容作为command的输⼊并执⾏之,若不指定n1,n2,则表⽰将整个⽂件内容作为command的输⼊:r!command:将命令command的输出结果放到当前⾏寄存器操作“?nyy:将当前⾏及其下n⾏的内容保存到寄存器?中,其中?为⼀个字母,n为⼀个数字“?nyw:将当前⾏及其下n个字保存到寄存器?中,其中?为⼀个字母,n为⼀个数字“?nyl:将当前⾏及其下n个字符保存到寄存器?中,其中?为⼀个字母,n为⼀个数字“?p:取出寄存器?中的内容并将其放到光标位置处。
linux文件编辑vi命令详解(Linux file editor VI command detailed)

linux文件编辑vi命令详解(Linux file editor VI commanddetailed)The VI editor is the standard editor for all Unix and Linux systems, and it is no less powerful than any of the latest text editors. Here's a brief introduction to how it works and a small portion of the instructions. Since the VI editor is identical to any version of the Unix and Linux systems, you can learn more about it in any other place where VI is introduced. The most basic text editor is Vi Linux, learn it, you can run in both directions unblockedly Linux in the world.1, the basic concepts of VIBasically, VI can be divided into three states, namely command mode (command, mode), mode mode (Insert mode) and last line mode, and the functions of each pattern are distinguished as follows:1) command line mode command mode)Control screen cursor movement, delete characters, words or rows, move, copy a section, and enter Insert mode, or to last line mode.2) insert mode (Insert mode)Only in Insert mode can you do text input, press the ESC key to return to command line mode.3) bottom line mode (last line mode)Save or exit the VI, or you can set the edit environment, such as finding strings and listing the line numbers...... Etc..But in general we use the simplified VI into two modes, is the bottom line mode (last line mode) on the command line command mode).2, the basic operation of VIA) enter VIAfter the system prompt symbol enters VI and file name, enter the VI full screen edit screen:$VI myfileBut one thing to pay special attention to is that after you enter VI, you are in the mode (command), and you have to switch to Insert mode to enter the text. The first use of VI people will want to use the arrow keys to move the cursor, the computer has been called bleep, his mad, so after entering the VI, the first not to move into "insert mode (Insert mode)"!B) switch to insert mode (Insert mode) to edit the fileUnder the command line mode (command mode), press the letter "I" to enter "Insert mode", then you can start typing.C) Insert switchingYou are currently in the "Insert mode" mode, and you can onlyenter the text all the time, if you find the wrong word! If you want to move back with the cursor keys, delete the word first, press the ESC key, go to command line mode (command mode), and then delete the text.D) quit VI and save the fileIn the command line mode (command mode), click ":" the colon key enters "Last line mode", for example:: W filename (enter "W filename") save the article as the specified file name filename.): WQ (enter WQ, save and exit VI): q! (enter Q, do not save, force VI)3, command line mode (command mode) function keys1) insert modePress "I" to switch to insert mode "insert mode", press "I" to enter the insert mode, then start the file from the current position of the cursor;When you press a to enter the insert mode, enter the text from the next position in the current cursor;According to the "O" into the insert mode, is to insert a new line, starting from the input text.2) switch from insert mode to command line modePress the "ESC" key.3) move cursorVI can move directly up and down with the cursor on the keyboard, but the regular VI uses lowercase English letters "H", "J", "K", "L", respectively, to control the cursor, left, bottom, top and right.Press "Ctrl" + "B": move the screen to the back.Press "Ctrl" + "F": move the screen to the front.Press "Ctrl" + "U": the screen moves back "half".Press "Ctrl" + "d": move the screen to the front "half page".Press the number "0": move to the beginning of the article.Press "G": move to the end of the article.According to the "$": move to cursor "at the end of the line".According to the "^": the move to cursor ""Press "W": the cursor jumps to the beginning of the next wordAccording to the "e": the cursor to jump to the next word suffixPress B to return the cursor to the beginning of the wordAccording to the "#l": the cursor to the line of the # position, such as: 5L, 56l.4) delete text"X": each time the cursor is deleted, a character is removed from the cursor's location."#x": for example, "6x" means the 6 characters of the back of the cursor where the cursor is deleted."X": uppercase X, and each time the cursor is deleted, a character in front of the cursor is deleted."#X": for example, "20X" means the 20 characters in front of the cursor where the cursor is deleted."DD": deletes the cursor's line."#dd": delete rows from the cursor to #5) copy"YW": the cursor to where the suffix characters are copied to the buffer."#yw": copy # words to the buffer"YY": copy the cursor line to the buffer."#yy": for example, "6yy" means copying 6 lines of text from the line in which the cursor is located."P": put the characters in the buffer to the cursor's location. Note: all replication commands associated with "Y" must work with "P" to complete copy and paste functions.6) replace"R": replaces the character at the cursor's location."R": replaces the character of the cursor wherever it goes, until the "ESC" button is pressed.7) reply to last operation"U": if you execute a command by mistake, you can press u at once and return to the previous operation. By multiple u, you can perform multiple replies.8) change"CW": the word to change the cursor at the end"C#w": for example, "c3w" means changing 3 words9) jump to the specified row"Ctrl" + "g" lists the line number of the cursor's line.For example: "#G", "15G", said the cursor to the fifteenth line of the.4, Last, line, mode, command BriefBefore using the "last line mode", remember to press the "ESC" button to make sure that you are already under "command mode", and then click "colon" to enter "last line mode".A) list the line numbers"Set Nu": when you enter "set Nu", you will list the line numbers in each line of the file.B) jump to a line in the file"#": "#" said a number, enter a number in the colon, then press the Enter key to jump to the bank, such as digital input 15, then enter, will jump to the fifteenth line.C) lookup characters/ keyword: press the "/" key first, then type the characters you want to search. If the keyword you want for the first time is not what you want, you can always press "n" to find the key you want."Keyword": press the "first" button first, and then enter the characters you want to find. If the first search key is not what you want, you can always press "n" to find the keyword you want.D) save the file"W": you can save the file by entering the letter "W" in the colon.E) leave VI"Q": press "Q" to quit. If you can't leave VI, you can force Q to leave VI with a "!"."QW": when you leave, it is generally recommended to be used with "W" so that you can save the file when you exit.5, VI command list1. The following table lists functions of some keys in command mode:HLeft shift cursor one characterLRight shift cursor one characterKcursor upJcursor down^Move the cursor to the beginning of the lineZeroThe number "0" moves the cursor to the beginning of the article GThe cursor moved to the end of the article$Move the cursor to the end of the lineCtrl+fFront screenCtrl+bBack flip screenCtrl+dMove the screenCtrl+uBack up the screenIInsert characters before cursor positionAAdded to the last character at the cursor's locationOInsert a new line, began to enter from theESCReturns from the input state to the command stateXDelete the characters behind the cursor#xThe character after the cursor has been deletedX(capitalize X). Delete the characters in front of the cursor#XRemove the cursor in front of # charactersDDDelete the line where the cursor is located#ddDelete where the number of rows from the cursor for the # YWA word that copies the cursor's location#ywCopy the current cursor position # wordsYYA row that copies the cursor's location#yyWhere the number of rows from the cursor to the copy for # PpasteUCancel operationCWA word that changes the location of the cursor#cwThe cursor changes the location of the # words2. The following table shows some instructions in the trip command modeW filenameSave the file being edited as filenameWQ filenameStore the file being edited as filename and exit VIQ!Drop all changes and exit VISet nuset numberOr /?Find what you want to search after / afterNUse with / or if the lookup is not a keyword you want to find, press n or backward (with / use) or forward (with), until you find it.For the first time with VI, there are a few points to note:1, after you open the file with VI, you are in the mode (command), and you have to switch to Insert mode to enter the text. Switch method: in the command line mode (command mode), click the letter "I", you can enter the "Insert mode" model, then you can start typing.2, after editing, you need to switch from the insert mode to the command line mode to save the file. Switch method: press the "ESC" button.3, save and exit the file: enter WQ in command mode! (don't forget the front of WQ)VI manualVI is the most commonly used text editing tool on UNIX, and as a UNIX software tester, it is necessary to master it.The command to enter VIVI filename: open or create a new file, and place the cursor on the first lineVI +n filename: open the file, and place the cursor on the N lineVI + filename: open the file, and place the cursor on the last lineVI +/pattern filename: open the file and place the cursor at the first string that matches the patternVI -r filename: the last time VI was edited, a system crash occurred, restoring filenameVI filename....filename: open multiple files, and edit them in turnMove cursor class commandsH: the cursor moves one character to the leftL: the cursor moves to the right one characterSpace: the cursor moves to the right one characterBackspace: the cursor moves one character to the leftK or Ctrl+p: move the cursor up one lineJ or Ctrl+n: move the cursor down one lineEnter: move the cursor down one lineW or W: the cursor to the right one word to doB or B: the cursor to the left one word to doE or E: the cursor to the right one word to the j suffix Cursor moved to the end of the sentence(cursor moved to the head of a sentence} move the cursor to the beginning of the paragraph {cursor moved to end of paragraphNG: the N cursor to the beginningN+: cursor down n lineN-: move the cursor up n linesN$: the N cursor to the end of the lineH: cursor moves to the top line of the screenM: cursor moves to the middle of the screenL: cursor moves to the last line of the screen(Note: 0 is the number zero) the cursor to the beginning of the current line$: the cursor to the end of the current lineScreen rollover class CommandCtrl+u: the first half turn to the fileCtrl+d: to the end of the file over the screenCtrl+f: flip a screen to the end of the fileCtrl + B; flip a screen to the top of the fileNZ: roll line n to the top of the screen and roll the current row to the top of the screen without specifying n.Insert text class CommandI: before the cursorI: at the beginning of the current lineA: after the cursorA: at the end of the current lineO: open a new line under the current lineO: new line on top of the current rowR: replace the current characterR: replaces the current character and its subsequent characters until the ESC key is pressedS: starting from the current cursor position, replacing the specified number of characters with the input textS: deletes the specified number of rows and replaces them with the input textNCW or nCW: modifies the specified number of wordsNCC: modifies the specified number of rowsDelete commandNDW or ndW: deletes the N-1 word at the beginning and after the cursorDo: to delete theD$: Delete to end of lineNDD: deletes the current row and its subsequent n-1 rowsX or X: deletes a character, X deletes the cursor, and the Xdeletes the cursorCtrl+u: delete the text entered under the input modeSearch and replace command:/pattern: search pattern from the end of the cursor at the end of the filePattern: search for the pattern from the cursor at the beginning of the fileN: repeat the last search command in the same directionN: repeat the last search command in the opposite direction: s/p1/p2/g: replace all P1 in the current line with P2: N1, n2s/p1/p2/g: all P1 in line N1 through N2 are replaced by P2: g/p1/s//p2/g: replace all the P1 in the file with P2Option settingAll: list all options settingsTerm: set terminal typeIgnorance: ignore case in searchList: Display tab (Ctrl+I) and the end of the line mark ($)Number: display line numbersReport: shows the number of lines modified by the line - oriented commandTerse: displays short warning messagesWarn: when you move to another file, the NO write information is displayed if the current file is not savedNomagic: allows you to use special characters in the search mode without "\" in frontNowrapscan: prohibit VI from searching at the end of the file and starting at the other endMESG: allows VI to display information written by other users to their terminals in writeLast line method command: N1, N2, Co, N3: copy the contents from the N1 line to the N2 line to line N3: N1, N2, m, N3: move the contents between the N1 line and the N2 line to line N3: N1, N2 D: delete the contents between the N1 rows and the N2 rows: W: save the current fileE filename: open the file filename for editing: X: save the current file and exit: Q: quit VI: Q: do not save the file and exit VI: Command: execute the shell command, command: N1, N2, W, command: the contents of the N1 to N2 line in the file are used as inputs and executed by the command, if notFixed N1, N2, which means that the entire file content as input to commandR: Command: put the output of the command command to the current line.。
Linux命令行中的文本编辑器vi和nano的使用技巧

Linux命令行中的文本编辑器vi和nano的使用技巧Linux操作系统广泛应用于服务器端和嵌入式设备,具有强大的灵活性和稳定性。
在Linux命令行中,文本编辑器是程序员和系统管理员经常使用的工具之一。
本文将介绍Linux命令行中常用的文本编辑器vi和nano的使用技巧。
一、vi文本编辑器的使用技巧vi是Linux系统中最常用的文本编辑器之一,虽然它具有一定的学习曲线,但一旦掌握了基本的使用技巧,它将成为你处理文本编辑的得力助手。
1. 打开文件:在命令行中输入vi命令,后跟要编辑的文件名。
例如,要编辑名为example.txt的文件,可以输入以下命令:vi example.txt。
如果文件不存在,则会创建一个新文件。
2. 进入编辑模式:打开文件后,vi默认处于命令模式,只能浏览文本,无法进行修改。
要进入编辑模式,按下键盘上的i键,即可开始编辑文本。
3. 保存并退出:在编辑模式下,对文本进行修改后,按下键盘上的Esc键,退出编辑模式。
然后输入冒号(:),即可看到光标出现在屏幕的底部命令行。
接下来,输入wq并按下回车键,即可保存修改并退出vi编辑器。
4. 取消修改并退出:在编辑模式下,对文本进行修改后,如果不想保存修改,可以按下键盘上的Esc键,退出编辑模式。
然后输入冒号(:),接着输入q!并按下回车键,即可取消修改并退出vi编辑器。
5. 移动光标:在命令模式下,可以使用方向键来移动光标,或使用h、j、k、l键分别向左、下、上、右移动光标。
此外,可以使用页键(Page Up和Page Down键)来进行快速翻页。
6. 复制、剪切和粘贴:在命令模式下,可以使用yy命令复制当前行,使用dd命令剪切当前行。
然后将光标移动到要粘贴内容的位置,按下p键即可将复制或剪切的内容粘贴到光标位置。
二、nano文本编辑器的使用技巧相较于vi而言,nano是一款更简单易用的文本编辑器,适合新手和不常使用命令行的用户。
下面介绍一些nano编辑器的基本使用技巧。
ubuntu下使用VI编辑文件必知的常用命令

u b u n t u下使用V I编辑文件必知的常用命令内部编号:(YUUT-TBBY-MMUT-URRUY-UOOY-DBUYI-0128)最近在使用ubuntu,已经很少进入windows平台了。
在linux下,要编辑文件或者其他的文本文件,哪那么一个ubuntu linux下的强大的文本编辑工具就不得不提了,那就是VI编辑器。
下面把VI常用到的命令行贴出来。
进入vi的命令vi filename :打开或新建文件,并将光标置于第一行首vi +n filename :打开文件,并将光标置于第n行首vi + filename :打开文件,并将光标置于最后一行首vi +/pattern filename:打开文件,并将光标置于第一个与pattern匹配的串处vi -r filename :在上次正用vi编辑时发生系统崩溃,恢复filenamevi filename….filename :打开多个文件,依次进行编辑移动光标类命令h :光标左移一个字符l :光标右移一个字符space:光标右移一个字符Backspace:光标左移一个字符k或Ctrl+p:光标上移一行j或Ctrl+n :光标下移一行Enter :光标下移一行w或W :光标右移一个字至字首b或B :光标左移一个字至字首e或E :光标右移一个字至字尾) :光标移至句尾( :光标移至句首}:光标移至段落开头{:光标移至段落结尾nG:光标移至第n行首n+:光标下移n行n-:光标上移n行n$:光标移至第n行尾H :光标移至屏幕顶行M :光标移至屏幕中间行L :光标移至屏幕最后行0:(注意是数字零)光标移至当前行首$:光标移至当前行尾屏幕翻滚类命令Ctrl+u:向文件首翻半屏Ctrl+d:向文件尾翻半屏Ctrl+f:向文件尾翻一屏Ctrl+b;向文件首翻一屏nz:将第n行滚至屏幕顶部,不指定n时将当前行滚至屏幕顶部。
插入文本类命令i :在光标前I :在当前行首a:光标后A:在当前行尾o:在当前行之下新开一行O:在当前行之上新开一行r:替换当前字符R:替换当前字符及其后的字符,直至按ESC键s:从当前光标位置处开始,以输入的文本替代指定数目的字符S:删除指定数目的行,并以所输入文本代替之ncw或nCW:修改指定数目的字nCC:修改指定数目的行删除命令ndw或ndW:删除光标处开始及其后的n-1个字do:删至行首d$:删至行尾ndd:删除当前行及其后n-1行x或X:删除一个字符,x删除光标后的,而X删除光标前的Ctrl+u:删除输入方式下所输入的文本搜索及替换命令/pattern:从光标开始处向文件尾搜索patternpattern:从光标开始处向文件首搜索patternn:在同一方向重复上一次搜索命令N:在反方向上重复上一次搜索命令:s/p1/p2/g:将当前行中所有p1均用p2替代:n1,n2s/p1/p2/g:将第n1至n2行中所有p1均用p2替代:g/p1/s//p2/g:将文件中所有p1均用p2替换选项设置all:列出所有选项设置情况term:设置终端类型ignorance:在搜索中忽略大小写list:显示制表位(Ctrl+I)和行尾标志($)number:显示行号report:显示由面向行的命令修改过的数目terse:显示简短的警告信息warn:在转到别的文件时若没保存当前文件则显示NO write信息nomagic:允许在搜索模式中,使用前面不带“”的特殊字符nowrapscan:禁止vi在搜索到达文件两端时,又从另一端开始mesg:允许vi显示其他用户用write写到自己终端上的信息最后行方式命令:n1,n2 co n3:将n1行到n2行之间的内容拷贝到第n3行下:n1,n2 m n3:将n1行到n2行之间的内容移至到第n3行下:n1,n2 d :将n1行到n2行之间的内容删除:w :保存当前文件:e filename:打开文件filename进行编辑:x:保存当前文件并退出:q:退出vi:q!:不保存文件并退出vi:!command:执行shell命令command:n1,n2 w!command:将文件中n1行至n2行的内容作为command的输入并执行之,若不指定n1,n2,则表示将整个文件内容作为command的输入:r!command:将命令command的输出结果放到当前行寄存器操作"nyy:将当前行及其下n行的内容保存到寄存器?中,其中为一个字母,n为一个数字"nyw:将当前行及其下n个字保存到寄存器?中,其中为一个字母,n为一个数字"nyl:将当前行及其下n个字符保存到寄存器?中,其中为一个字母,n为一个数字"p:取出寄存器?中的内容并将其放到光标位置处。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Linux环境下vi命令编辑器详解(FedoraUbuntu...)Linux环境下vi命令编辑器详解(Fedora/Ubuntu/.../) 2008-12-19 16:43一、Unix编辑器概述编辑器是使用计算机的重要工具之一,在各种操作系统中,编辑器都是必不可少的部件。
Unix及其相似的ix 操作系统系列中,为方便各种用户在各个不同的环境中使用,提供了一系列的ex编辑器,包括ex, edit,ed 和vi.其中ex,edit,ed都是行编辑器,现在已很少有人使用,Unix提供他们的原因是考虑到满足各种用户特别是某些终端用户的需要。
值得庆幸的是,Unix提供了全屏幕的Vi编辑器,这使我们的工作轻松不少。
不少DOS用户抱怨Vi编辑器不象DOS下的编辑器如edit那么好用,这是因为Vi考虑到各种用户的需要,没有使用某些通用的编辑键(在各个不同的终端机上他们的定义是不同的,在某些终端机上甚至没有这些键)。
而是采用状态切换的方法,但这只是习惯的问题,一旦你熟练的使用上了vi你就会觉得它其实也很好用。
虽然Vi采用了状态切换的方法,但电脑的硬件及操作系统多种多样,某些电脑的键盘上没有特定的几个功能键!那麽不就有某些功能不能用了?这个问题在Unix 系统上也一样,几乎各大电脑厂商都有自己的Unix 系统,而vi 的操作方法也会随之有点出入。
这里我们采用PC 的键盘来说明vi 的操作,但在具体的环境中还要参考相应的资料,这一点是值得注意的。
二、Vi入门(一)、进入vi在系统提示字符(如$、#)下敲入vi <档案名称>,vi 可以自动帮你载入所要编辑的文件或是开启一个新文件(如果该文件不存在或缺少文件名)。
进入vi 后萤幕左方会出现波浪符号,凡是列首有该符号就代表此列目前是空的。
(二)、两种模式如上所述,vi存在两种模式:指令模式和输入模式。
在指令模式下输入的按键将做为指令来处理:如输入a,vi 即认为是在当前位置插入字符。
而在输入模式下,vi则把输入的按键当作插入的字符来处理。
指令模式切换到输入模式只需键入相应的输入命令即可(如a,A),而要从输入模式切换到指令模式,则需在输入模式下键入ESC键,如果不晓得现在是处於什麽模式,可以多按几次[ESC],系统如发出哔哔声就表示已处于指令模式下了。
付:在指令模式进入输入模式的指令:新增(append)a :从光标所在位置後面开始新增资料,光标後的资料随新增资料向後移动。
A:从光标所在列最後面的地方开始新增资料。
插入(insert)i:从光标所在位置前面开始插入资料,光标後的资料随新增资料向後移动。
I :从光标所在列的第一个非空白字元前面开始插入资料。
开始(open)o :在光标所在列下新增一列并进入输入模式。
O: 在光标所在列上方新增一列并进入输入模式。
(三)、退出vi在指令模式下键入:q,:q!,:wq或:x(注意:号),就会退出vi。
其中:wq和:x是存盘退出,而:q是直接退出,如果文件已有新的变化,vi会提示你保存文件而:q命令也会失效,这时你可以用:w命令保存文件后再用:q 退出,或用:wq或:x命令退出,如果你不想保存改变后的文件,你就需要用:q!命令,这个命令将不保存文件而直接退出vi。
(四)、基本编辑配合一般键盘上的功能键,像是方向键、[Insert] 、[Delete] 等等,现在你应该已经可以利用vi 来编辑文件了。
当然vi 还提供其他许许多多功能让文字的处理更为方便。
何谓编辑?一般认为是文字的新增、修改以及删除,甚至包括文字区块的搬移、复制等等。
先这里介绍vi 的如何做删除与修改。
(注意:在vi 的原始观念里,输入跟编辑是两码子事。
编辑是在指令模式下操作的,先利用指令移动光标来定位要进行编辑的地方,然後才下指令做编辑。
)删除与修改文件的命令:x:删除光标所在字符。
dd :删除光标所在的列。
r :修改光标所在字元,r 後接著要修正的字符。
R:进入取替换状态,新增文字会覆盖原先文字,直到按[ESC]回到指令模式下为止。
s:删除光标所在字元,并进入输入模式。
S:删除光标所在的列,并进入输入模式。
其实呢,在PC上根本没有这麽麻烦!输入跟编辑都可以在输入模式下完成。
例如要删除字元,直接按[Delete] 不就得了。
而插入状态与取代状态可以直接用[Insert] 切换,犯不著用什麽指令模式的编辑指令。
不过就如前面所提到的,这些指令几乎是每台终端机都能用,而不是仅仅在PC 上。
在指令模式下移动光标的基本指令是h, j, k, l 。
想来各位现在也应该能猜到只要直接用PC 的方向键就可以了,而且无论在指令模式或输入模式下都可以。
多容易不是。
当然PC 键盘也有不足之处。
有个很好用的指令u 可以恢复被删除的文字,而U 指令则可以恢复光标所在列的所有改变。
这与某些电脑上的[Undo] 按键功能相同。
三、附件:vi详细指令表进入vi的命令vi filename: 打开或新建文件,并将光标置于第一行首vi +n filename: 打开文件,并将光标置于第n行首vi + filename: 打开文件,并将光标置于最后一行首vi +/pattern filename: 打开文件,并将光标置于第一个与pattern匹配的串处vi -r filename: 在上次正用vi编辑时发生系统崩溃,恢复filenamevi filename....filename: 打开多个文件,依次进行编辑移动光标类命令h: 光标左移一个字符l: 光标右移一个字符space: 光标右移一个字符Backspace: 光标左移一个字符k或Ctrl+p: 光标上移一行j或Ctrl+n: 光标下移一行w或W : 光标右移一个字至字首b或B : 光标左移一个字至字首e或E : 光标右移一个字至字尾): 光标移至句尾(: 光标移至句首}: 光标移至段落开头{: 光标移至段落结尾nG: 光标移至第n行首n+: 光标下移n行n-: 光标上移n行H: 光标移至屏幕顶行M: 光标移至屏幕中间行L: 光标移至屏幕最后行0: 光标移至当前行首$: 光标移至当前行尾屏幕翻滚类命令Ctrl+u: 向文件首翻半屏Ctrl+d: 向文件尾翻半屏Ctrl+f: 向文件尾翻一屏Ctrl+b: 向文件首翻一屏nz: 将第n行滚至屏幕顶部,不指定n时将当前行滚至屏幕顶部。
插入文本类命令i: 在光标前I: 在当前行首a: 光标后A: 在当前行尾o: 在当前行之下新开一行O: 在当前行之上新开一行r: 替换当前字符R: 替换当前字符及其后的字符,直至按ESC键s: 从当前光标位置处开始,以输入的文本替代指定数目的字符S: 删除指定数目的行,并以所输入文本代替之ncw或nCW: 修改指定数目的字nCC: 修改指定数目的行删除命令ndw或ndW: 删除光标处开始及其后的n-1个字do: 删至行首d$: 删至行尾ndd: 删除当前行及其后n-1行x或X: 删除一个字符,x删除光标后的,而X删除光标前的Ctrl+u: 删除输入方式下所输入的文本搜索及替换命令/pattern: 从光标开始处向文件尾搜索patternpattern: 从光标开始处向文件首搜索patternn: 在同一方向重复上一次搜索命令N: 在反方向上重复上一次搜索命令:s/p1/p2/g: 将当前行中所有p1均用p2替代:n1,n2s/p1/p2/g: 将第n1至n2行中所有p1均用p2替代:g/p1/s//p2/g: 将文件中所有p1均用p2替换选项设置all:列出所有选项设置情况term:设置终端类型ignorance:在搜索中忽略大小写list:显示制表位(ctrl+i)和行尾标志($)number:显示行号report:显示由面向行的命令修改过的数目terse:显示简短的警告信息warn:在转到别的文件时若没保存当前文件则显示no write 信息nomagic:允许在搜索模式中,使用前面不带“\”的特殊字符nowrapscan:禁止vi在搜索到达文件两端时,又从另一端开始mesg:允许vi显示其他用户用write写到自己终端上的信息最后行方式命令:n1,n2 co n3:将n1行到n2行之间的内容拷贝到第n3行下:n1,n2 m n3:将n1行到n2行之间的内容移至到第n3行下:n1,n2 d :将n1行到n2行之间的内容删除:w :保存当前文件:e filename:打开文件filename进行编辑:x:保存当前文件并退出:q:退出vi:q!:不保存文件并退出vi:!command:执行shell命令command:n1,n2 w!command:将文件中n1行至n2行的内容作为command的输入并执行之,若不指定n1,n2,则表示将整个文件内容作为command的输入:r!command:将命令command的输出结果放到当前行寄存器操作"?nyy:将当前行及其下n行的内容保存到寄存器?中,其中为一个字母,n为一个数字"?nyw:将当前行及其下n个字保存到寄存器?中,其中为一个字母,n为一个数字"?nyl:将当前行及其下n个字符保存到寄存器?中,其中为一个字母,n为一个数字"?p:取出寄存器?中的内容并将其放到光标位置处。
这里?可以是一个字母,也可以是一个数字ndd:将当前行及其下共n行文本删除,并将所删内容放到1号删除寄存器中。