Vim技巧

修改文件

A HAPPY END WITH YEAR 2013!-> A HAPPY NEW YEAR 2014!
fEc2wNEW#ESC#f3r4ZZ

注:
f表示find,fE表示向前查找第一个E,F则指向左查找,FE找寻左边第一个E。
c指擦除,w指word,cw指擦除当前一个word,c2w指向前擦除2个word,执行完cw进入insert模式。
r指replace,r4指将当前字符替换成4,5r4就是把当前连续5个字符替换成4。
Z+Z 连续按下两次Z,文件将保存并退出vim.

*temp var1 0
*temp var2 "hi"
*temp var3 -1
*temp var4 42
*temp var5 "asdf"
*temp var6 0


Simple things we do all the time should be able to be done with very few keystrokes, but sometimes I find something I need to do makes me go, "There MUST be a better way."

This challenge is just a simple movement and entering text at a certain place.

->

*temp var1 0
*temp var2 "hi"
*temp var3 -1
*temp var4 42
*temp var5 "asdf"
*temp var6 0
*temp var7 11


Simple things we do all the time should be able to be done with very few keystrokes, but sometimes I find something I need to do makes me go, "There MUST be a better way."

New text.

This challenge is just a simple movement and entering text at a certain place.

EEr7ecw11#ESC#}}oNEW text#CR##ESC#:wq#CR#
Y:复制一行
}:定位到代码块结束
{:定位到代码块开始
P:paste粘贴一行
E:end移动到下一个单词末尾
B:begin移动到单词首

dG:删除到结束
gJ:多行合并成一行,5gJ表示5行合并成一行。
:s/* /,/g:替换操作,将* 替换成,。
x:删除当前字符。

修改文件

foo = a ab abc

->

foo = "a"
      "ab"
      "abc"

solution1:2w#C-V#jjI”#ESC#GA”#ESC#k.k.ZZ

2w:跳过两个单词。
. :Repeats the last change made in normal mode
5. :Repeats 5 times the last change made in normal mode
k or Up Arrow: move the cursor up one line
A or a:在当前文字后面插入。

solution2:Gqaciw”#C-R#”“#ESC#Kq2@aZZ
宏命令(Macros):

:qx 开始记录宏,并将结果存入寄存器x
q 退出记录模式
@x 播放记录在x寄存器中的宏命令

你可能感兴趣的:(vim)