vim 实用命令整理

  1. :1,$s/storage1/datastore1/g //替换所有storage1为datasore1
  2.  7|  //查找当前行第7列
  3. 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.
  4. g/del/d  删除含有del的行
  5.  set vim line numbers by default
    Add set number to your .vimrc file in your home directory.
  6. :%s/old/new/gc //替换old为new,每次替换都需要用户确认
  7. :/the\> //精确查找the
  8. % 可以让光标从它当前所在的括号跳转到与它相匹配的括号上去, 对花括号和
    圆括号, 方括号都有效, 常用于手工检查括号是否匹对.
  9. set hlsearch //设置查找字符高亮显示

       nohlsearch //取消高亮显示

  10. vi -o file1.txt file2.txt //一个terminal水平打开file1和file2, 可以使用vi --help查看具体命令含义

  11. ab: asap as soon as possible //定义缩写
  12. :x 等于:wq
  13. vsp 另一个文件名 //把当前窗口竖着分开
  14. 1,12!sort -r -n -k4.1,5

    -r 是降序排序
    -n 是按数字大小排序
    -k,表示根据那个字段排序,4.1,表示第4列第一个字符开始 ,5表示到第5个字段为结束
    -t 后面跟分隔符,缺省是空格
  15. :w !sudo tee % //以root方式直接保存
  16. 第二次输入一个“compiler”时, 输入“com”,然后Ctrl + n//自动补全单词
  17. $vimdiff 1.txt 2.txt //比较两个文件的不同 或 vi 1.txt->:diffthis->:vsp 2.txt->:windo diffthis ->diffoff
  18. :earlier 1m //把文件回退到1分钟以前的状态  :later //进行相反的操作
  19. Ctrl+o和Ctrl+i //在编辑文件处来回跳转
  20. 在行首yG(复制整个文件), 到需要粘贴处,‘p’(粘贴)
  21. Here is how to cut-and-paste or copy-and-paste text using a visual selection in Vim.

    Cut and paste:

    1. Position the cursor where you want to begin cutting.
    2. Press v to select characters (or uppercase V to select whole lines).
    3. Move the cursor to the end of what you want to cut.
    4. Press d to cut (or y to copy).
    5. Move to where you would like to paste.
    6. 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值