vim base command, Find and Replace

vim basic Find and Replace command

vim simple commands with the okay. Such as insert, delete, query. But replacing it with less. So, still we need to use the time out to see the controls.

Use vim to edit the file:

vim xxx

After entering the interface is called command mode interface. You can modify the file when editing is called the insert mode.

(Command mode) instruction colon +

In vim command mode interface you want to quit, you need to enter the colon and instructions

:wq   保存并退出
:q  维修改退出
:q! 强制退出并不保存

(Command mode) to move the cursor

In vim interface, the command cursor movement mode method

1、使用上下左右方向键

2、命令模式下:
h   向左
j   向下 
k   向上
l  向右

空格键 向右
Backspace  向左
Enter  移动到下一行首
-  移动到上一行首。

:set  nu     //显示行号
:set nonu    //取消显示行号
n+        //向下跳n行
n-         //向上跳n行
nG        //跳到行号为n的行
G           //跳至文件的底部
g         //跳转到文件头部

(Insert mode) Edit Mode

Button to enter the insert mode edit

a      //在当前光标位置的右边添加文本
i       //在当前光标位置的左边添加文本
A     //在当前行的末尾位置添加文本
I      //在当前行的开始处添加文本(非空字符的行首)
O     //在当前行的上面新建一行
o     //在当前行的下面新建一行
R    //替换(覆盖)当前光标位置及后面的若干文本
J    //合并光标所在行及下一行为一行(依然在命令模式)

ESC to exit edit mode

(Command mode) delete and copy

In vim, in addition to modify the file in edit mode, command mode when you can delete and copy

x         //删除当前字符
nx         //删除从光标开始的n个字符
dd       //删除当前行
ndd      //向下删除当前行在内的n行
u        //撤销上一步操作
U        //撤销对当前行的所有操作
yy       //将当前行复制到缓存区,也可以用 "ayy 复制,"a 为缓冲区,a也可以替换为a到z的任意字母,可以完成多个复制任务。
nyy      //将当前行向下n行复制到缓冲区,也可以用 "anyy 复制,"a 为缓冲区,a也可以替换为a到z的任意字母,可以完成多个复制任务。
yw       //复制从光标开始到词尾的字符。
nyw      //复制从光标开始的n个单词。
y^       //复制从光标到行首的内容。  VPS侦探
y$       //复制从光标到行尾的内容。
p        //粘贴剪切板里的内容在光标后,如果使用了前面的自定义缓冲区,建议使用"ap 进行粘贴。
P        //粘贴剪切板里的内容在光标前,如果使用了前面的自定义缓冲区,建议使用"aP 进行粘贴。

(Command mode) search and replace

Command mode (esc exit insert mode)

/keyword     //向光标下搜索keyword字符串,keyword可以是正则表达式
?keyword     //向光标上搜索keyword字符串
n           //向下搜索前一个搜素动作
N         //向上搜索前一个搜索动作

*(#)      //当光标停留在某个单词上时, 输入这条命令表示查找与该单词匹配的下(上)一个单词. 同样, 再输入 n 查找下一个匹配处, 输入 N 反方向查找.

g*(g#)        //此命令与上条命令相似, 只不过它不完全匹配光标所在处的单词, 而是匹配包含该单词的所有字符串.

:s/old/new      //用new替换行中首次出现的old
:s/old/new/g         //用new替换行中所有的old
:n,m s/old/new/g     //用new替换从n到m行里所有的old
:%s/old/new/g      //用new替换当前文件里所有的old

Guess you like

Origin www.cnblogs.com/woshimrf/p/vim.html