vim替换
替换全局
:%s/word1/word2/g
将全文中的word1替换为word2。“/g”替换为“/gc”后会在替换前显示提示字符给用户确认。
替换前:this is word1
替换后:this is word2
替换局部
:1,10s/word1/word2/g
将第1行到第10行的word1替换为word2
替换前:this is word1
替换后:this is word2
替换行首
:%s/^/hello /g
替换前:this is word1
替换后:hello this is word1
替换行位
:%s/$/ end;/g
替换前:this is word1
替换后:this is word1 end;
前后插入
:%s/.*/drop table & purge;/g
替换前:test1
替换后:drop table test1 purge;