vi常用命令以及快捷键

Posted by Clear Blog on February 16, 2018

因为日常开发中需要用vi来查看日志文件以及配置文件等等,所以为了提高效率,记录常用命令。

  1. 查找并替换字符串 带%,所有行;不带%,当前行 带g,第一个;不带g,所有
    1
    2
    3
    4
    
     :%s/data_status/data_state/     // 将所有行中第一个data_status替换成data_state 
     :%s/data_status/data_state/g    // 将所有行中所有data_status替换成data_state 前面是source,后面是target
     :s/data_status/data_state/      // 将所有行中第一个data_status替换成data_state 前面是source,后面是target
     :s/data_status/data_state/g     // 将所有行中所有data_status替换成data_state 前面是source,后面是target
    
  2. 光标移动

G 跳到文件末 H/M/L 跳到当前页顶部、中部、底部 db 删除光标前面的字(当前行) d 删除光标后面的字(当前行) ^ 移到第一个非空字符(当前行) $ 移到最后一个字符(当前行) ( 移到句子的开头 ) 移到句子的结尾 { 移到段落的开头 } 移到下一个段落的开头 w 移到下一个字的开头 b 移到前一个字的开头 e 移到下一个字的结尾