VIM 编辑器之神

2018-09-27  本文已影响0人  bfx1000

说明:在这篇文章里面,<C-X> 代表 Ctrl + X——就是按住 Ctrl 键然后再按 X

vim三种模式

insert模式 按i 进入
normal模式 按ESC进入
virtual模式 按:进入
v可视化选择是一个很有意思的命令,你可以先按v,然后移动光标,你就会看到文本被选择
然后,你可能d,也可y,也可以变大写等

edit an existing file within vim.

:e d:test2.txt
#cmd prompt
vim d:cajview/welcome.txt

save a file as the aim path

saveas c:test2.txt
saveas c:\Users\administrator\Desktop\test2.txt
saveas c:/Users/administrator/Desktop/test2.txt
saveas ~/Desktop/test2.txt

大小写转换

gU (变大写)
gu (变小写)

vim文本编辑----移动(move)

0 → 到行头
$ → 到行尾
^ → 到本行的第一个非blank字符
<C-f>mean page down
<C-b>mean page up
normal模式下:
h、j、k、l分别代表左、下、上、右
0 移动到行首
$ 移动到行尾
gg 移动到篇首
G 移动到篇尾
79gg  跳转到79行(79G)
30j  means move down 30 lines
2w  move behind 2 words' beginning
3e  move behind 3 words and locate the end of third word
ce  erase a word and insert mode
0y$ means copy a line from beginning to end
ye means copy a word from current position
y2/foo means copy string between the first foo and the second foo

vim文本编辑----查找和替换(select and replace)

w 移动到下一个单词字首
e 移动到当前单词尾
f {char} F{char} 查找下\上一个字符,之后按;继续查找
t{char} T{char} 向后/前查找单个字符左侧字符,之后按;继续查找
:%s/i'm/I'm/g 全局替换把i'm替换成I'm
:n1,n2s/word1/word2/g   means replace word1 with word2

select

/tihuan
to select string "tihuan" in full text, button "n" to select the next, 
"N" opposite select.
?tihuan
to select string above from current position

vim文本编辑----insert

i  insert before cursor 
a  append after cursor
A  append something at the last of a line
o  insert a void row below cursor
O  insert a void row above cursor

vim文本编辑----删除(delete)

normal模式下,
x  删除当前光标一个字符,接着用.重复删除字
dd 删除一行数据,然后用.重复删除一行数据 
dw 删除到下一个单词
de 删除本单词
d$ 删除从光标到行尾
dG 删除从光标到结尾

段落删除

delete 1 row\delete 1-10 rows
:1d
:1,10d

vim文本编辑----复制粘贴(copy&paste)

yy #copy the current line to your clipboard
2yy 复制本行和下面1行
:reg 查看各个黏贴板内容
"2p 粘贴2号剪切板
"+y 复制到系统剪切板
"+p 黏贴系统剪切板内容

点操作
# <backspace>和正常的输入都将作为命令的一部分, 且该命令是可以重复执行的。通过 . 来实现
d剪切,p粘贴,例如剪切一行并粘贴
dd
p


vim多行复制(或几个单词复制)

移动光标到复制开始的地方按V,移动光标到复制结束的地方按y,移动到粘贴位置按P

vim文本编辑----新建与保存

在默认路径 **c:\\Users\\用户名** 下新建一个名为welcome.txt的文件并打开(在cmd中)
vim welcome.txt
# 退出且不保存
:q!<ENTER>
# 保存退出
:wq<ENTER>
# 对未命名文件命名为 welcome.txt
:file welcome.txt
对于没有指定 Vim 的保存文件路径,指定路径
:cd c:\User\admin

vim文本编辑----缩进

单行缩进,normal下,当前段落*向左、向右*缩进分别是:
<<
>>
批量缩进,normal下,2到9行向右缩进一个tab/两个tab
:2,9> 
:2,9>>

the dot order

. → (小数点) 可以重复上一次的命令
N<command> → 重复某个命令N次

2dd → 删除2行
3p → 粘贴文本3次
3idesu [ESC] → 会写下 “desu desu desu“
. → 重复上一个命令—— 3 “desu “.
2. → 重复 2次 “desu” (注意:不是 6 times,你看,VIM多聪明啊).

Annotation many lines

VISUAL mode select targets
ctrl+v
Input upper case 'I'
Input #
上一篇 下一篇

猜你喜欢

热点阅读