vi笔记2——vi之简单编辑

vi笔记2——vi之简单编辑

vi 简单编辑主要包含以下内容:
• Moving the cursor
• Adding and changing text
• Deleting, moving, and copying text
• More ways to enter insert mode


相关命令说明如下:

c,d,y can use like this
(number)(cmd)(text object)
(cmd)(number)(text object)

a --append text after cursor
A or $a --append text at the end of the line

c 命令行下使用c,就会从光标处清除相应的字符
cc --to replace the entire current line,equal to S(large)
C(large c) --equal to c$ ,replace words from current cursor to the end of the line
cw --To the end of a word
c2b --Back two words
c$ --To the end of line
c0 --To the beginning of line

d --delete
ndd --delete n lines from current line
d2w 2dw --delete two words
db --delete backward
D or d$ -- deletes from the cursor position to the end of the line
d0 -- delete to the beginning of a line
de --To retain the space between words, use de, which deletes only to the end of a word.
dE --deletes to the end of a word, including punctuation.

ngg --go to line n,equal to nG
1gg --go to line 1,equal to command mode(:1)
$g or G --go to the last line of the file,equal to command mode(:$)

nh --move n space to the left

i --insert before the corsor
typing 25a*- or 25i*- ESC appends or inserts 50 characters (25 pairs of asterisk and hyphen).
 I  --insert at the head of a line

nj --down n lines
J --join,Joining Two Lines with J,nJ will join n lines

nk --up n lines

nl --right n space

o(small o) --Open blank line  below cursor for text.
create a new line after current line,and be inserting mode 
O(large O) --Open blank line above cursor for text.
create a new line before current line,and be inserting mode

p --put, d x yy后的缓存数据可以直接用来粘贴
If you delete one or more lines, p puts the deleted text on a new line(s) below the cursor. If you delete less than an entire line, p puts the deleted text into the current line, after the cursor.

r or R-- (replace)选中某个字符,并且设置为可改变状态,如:rs将选中的字符变为s,rw将选中的字符变为w,2rs将两个字符变为s
R (“large” replace) is useful when you want to start changing text, but you don’t know exactly how much.
小r只能替换一个字符,大R可以从当前光标处不停的替换

s(small s) --Substituting text,substitute a single character,and be inserting mode
ns will substitute n characters
S(large s) --lets you change whole lines,equal to cc,put you in inssert mode
nS --change n lines,equal to ncc

u --undo,undo your last undo with u,如果误删了数据,如dd某一行,可以使用u来撤销上一次的命令,p命令也可以粘贴删除的内容(x dd等内容在缓存中,用可以p来粘贴),(VI)page 296 has more undoing functions.
U, the uppercase version of u, undoes all edits on a single line, as long as the cursor remains on that line. Once you move off a line, you can no longer use U.
Vim lets you use CTRL-R to “redo” an undone operation.

w word,以一个块为单位的移动

x --deletes only the character the cursor is on
nx --delete n characters from the cursor
nX --delete n characters before the cursor
说明:点(.),当使用x后点和小x一样删除光标右边的,当使用大X后点和大X一样删除光标左边的
 
y --yank
nyy or nY --copy n lines
yw --copy one word
y$ --copy to the end of a line
y0 --copy to the begin of a line

~ --The tilde (~) command will change a lowercase letter to uppercase or an uppercase letter to lowercase.

.(dot) --Repeating or Undoing Your Last Command

summary:
Table 2-1. Edit commands
Text object			        Change 			Delete 			Copy
One word        	                cw 			dw 			yw
Two words,not counting punctuation      2cW or c2W              2dW or d2W              2yW or y2W
Three words back                        3cb or c3b 		3db or d3b 		3yb or y3b
One line 			        cc 			dd 			y or Y
To end of line 	                        c$ or C 		d$ or D 		y$
To beginning of line                    c0 		        d0 			y0
Single character 	                r 			x or X 			yl or yh
Five characters 	                5s 			5x 			5yl

Table 2-2. Movement
Movement Commands
← , ↓ , ↑ , → h, j, k, l
To first character of next line 	 	                +
To first character of previous line                             -
To end of word 							e or E
Forward by word  						w or W
Backward by word 						b or B
To end of line  						$
To beginning of line  					        0

Table 2-3. Other operations
Operations Commands
Place text from buffer 					P or p
Start vi, open file if specified  		        vi file
Save edits, quit file 					ZZ or :wq
No saving of edits, quit file  			        :q!

Table 2-4. Text creation and manipulation commands
Editing action Command
Insert text at current position  		i
Insert text at beginning of line   		I
Append text at current position  		a
Append text at beginning of line  		A
Open new line below cursor for new text         o(小写字母 欧)
Open new line above cursor for new text         O(大写字母 欧)
Delete line and substitute text  		S
Overstrike existing characters with new text    R
Join current and next line  			J
Toggle case  					~
Repeat last action  				.
Undo last change  				u
Restore line to original state  		U


以上是学习vim时候整理的一些要点,分享此处以供学习!

对于一些想深入学习vi的人群,可以参考以下图书:Learning.the.vi.and.Vim.Editors.7th

下载链接: http://download.csdn.net/detail/u011127242/9617946

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昕光xg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值