- :1,$s/storage1/datastore1/g //替换所有storage1为datasore1
- 7| //查找当前行第7列
- set autoindent //Now, when you are inserting text, if you press
Enter
atthe end of your text, vi will automatically indent the nextnew line to match the indent of the previous one. g/del/d 删除含有del的行
- set vim line numbers by default
Addset number
to your.vimrc
file in your home directory. - :%s/old/new/gc //替换old为new,每次替换都需要用户确认
- :/the\> //精确查找the
- % 可以让光标从它当前所在的括号跳转到与它相匹配的括号上去, 对花括号和
圆括号, 方括号都有效, 常用于手工检查括号是否匹对. set hlsearch //设置查找字符高亮显示
nohlsearch //取消高亮显示
vi -o file1.txt file2.txt //一个terminal水平打开file1和file2, 可以使用vi --help查看具体命令含义
- ab: asap as soon as possible //定义缩写
- :x 等于:wq
- vsp 另一个文件名 //把当前窗口竖着分开
- 1,12!sort -r -n -k4.1,5
-r 是降序排序
-n 是按数字大小排序
-k,表示根据那个字段排序,4.1,表示第4列第一个字符开始 ,5表示到第5个字段为结束
-t 后面跟分隔符,缺省是空格 - :w !sudo tee % //以root方式直接保存
- 第二次输入一个“compiler”时, 输入“com”,然后Ctrl + n//自动补全单词
- $vimdiff 1.txt 2.txt //比较两个文件的不同 或 vi 1.txt->:diffthis->:vsp 2.txt->:windo diffthis ->diffoff
- :earlier 1m //把文件回退到1分钟以前的状态 :later //进行相反的操作
- Ctrl+o和Ctrl+i //在编辑文件处来回跳转
- 在行首yG(复制整个文件), 到需要粘贴处,‘p’(粘贴)
Here is how to cut-and-paste or copy-and-paste text using a visual selection in Vim.
Cut and paste:
- Position the cursor where you want to begin cutting.
- Press v to select characters (or uppercase V to select whole lines).
- Move the cursor to the end of what you want to cut.
- Press d to cut (or y to copy).
- Move to where you would like to paste.
- Press P to paste before the cursor, or p to paste after.
Copy and paste is performed with the same steps except for step 4 where you would press y instead of d:
- d = delete = cut
- y = yank = copy
vim 实用命令整理
最新推荐文章于 2021-04-14 17:37:39 发布