📄 l3.2
字号:
#print Basic Alteration - Insert and Delete II Now we'll see how to change things at a larger scale than individualcharacters. Suppose you wanted to put a blank line into your file. You coulduse the A command to start inserting at the end of the line, hit return andthen hit Escape. That would do it, but there's an easier way. The o and Ocommands 'open' a new line either after or before the current line. You canthen add more text if you like and hit Escape when you're done to get out ofinsert mode. 'o' opens a blank line after the current one and O does it beforethe current one. To get rid of a line, just move to that line and hit 'dd'. That's reallytwo d's there, not one. This is a single case of a more general command whichwe'll look at later. If you want to change a line, i.e. delete the old one andtype a new one in its place, move to the line and type 'cc'. We'll see moreof the d and c commands later. Type 'ready' (as usual) to practice these commands and learn some others.#user#create Insert2 The commands for opening up new blank lines are o (to open one after thecurrent line) and O (to open one before the current line). The dd command will delete the current line and the cc command will bothdelete it and let you type in a replacement. You can try these out on thesample text after the dashed line below. You may notice when you use the dd command that the lines don't seem togo away entirely. There always seems to be a line with an at-sign (@) onit where the old lines were. This only happens on so-called 'dumb' terminalswhich can't quickly delete lines. Those lines aren't really in the file (as you'll see if you try to move onto them), they're just a convenienceso that vi doesn't have to take the time to redraw a lot of your screen every time you delete a line. You can use the ^R command to 'repair' thescreen at any time. Try it! Another handy command for changing text is the r command to replace acharacter. If you only need to turn one character into another, just movethe cursor to the character in question and hit r followed by the newcharacter. This will replace the old one. If you want to overwrite morethan one character, use the R command. You move to the first character tobe overwritten, type R, type the new text over the old, and hit Escape toleave overwrite mode. The last command we'll look at here is the s command, for substitutingcharacters. Suppose there is a character you want to replace with morethan one other characters. Just move to the old character, type s, typethe new characters, and hit Escape to leave substitution mode. If youneed to substitute for more than one character, you can just precede thes command with a count. For example, to replace 3 characters with 5 others,move to the first character to be replaced, type 3s, type the 5 new charactersand hit Escape. We've just looked at a lot of commands at once. Spend enough timepracticing them so that you'll remember them well. They're the commandsyou'll end up using most frequently.---------------------------------------------------------------#cat /usr/lib/learn/vi/longtext >> Insert2vi Insert2#next3.3 10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -