xx11,xx12,xx13 " find replacement text, put in memory, then use \zs to simplify
substitute :%s/"\([^.]\+\).*\zsxx/\1/ " Pull word under cursor into LHS of a substitute :nmap z :%s#\<=expand("")\># " Pull Visually Highlighted text into LHS of a substitute :vmap z :%s/\<*\>/ ---------------------------------------- " all following performing similar task, substitute within substitution " Multiple single character substitution in a portion of line only :%s,\(all/.*\)\@<=/,_,g : replace all / with _ AFTER "all/" " Same thing :s#all/\zs.*#\=substitute(submatch(0), '/', '_', 'g')# " Substitute by splitting line, then re-joining :s#all/#&^M#|s#/#_#g|-j! " Substitute inside substitute :%s/.*/\='cp '.submatch(0).' all/'.substitute(submatch(0),'/','_','g')/ ---------------------------------------- " 全局显示命令 :g/gladiolli/# : 查找并显示匹配的行号 :g/fred.*joe.*dick/ : 显示所有含有 fred,joe & dick的行 :g/\/ : 显示单一单词fred :g/^\s*$/d : 删除所有空行 :g!/^dd/d : 删除不含字符串''dd''的行 :v/^dd/d : 同上 :g/fred/,/joe/d : 删除所有的从fred到joe :g/-------/.-10,.d : 以-------为标记删除之前的10行 :g/{/ ,/}/- s/\n\+/\r/g : 删除 {...}之间的空行 :v/\S/d : Delete empty lines (both types) :v/./,/./-j : 压缩空行 :g/^$/,/./-j : 同上 :g/:g/^/put_ : 双倍行宽 (pu = put) :g/^/m0 : 颠倒文件 (m = move) :'a,'bg/^/m'b : 颠倒选中的 a 到 b :g/^/t. : 重复行 :g/fred/t$ : 拷贝行从fred到结尾 :g/stage/t'a : 拷贝行从stage 到 marker a(a为标记的位置) :g/\(^I[^^I]*\)\{80}/d : 删除最少包含80个tab的行 " perform a substitute on every other line :g/^/ if line('.')%2|s/^/zz / " match all lines containing "somestr" between markers a & b " copy after line containing "otherstr" :'a,'bg/somestr/co/otherstr/ : co(py) or mo(ve) " as above but also do a substitution :'a,'bg/str1/s/str1/&&&/|mo/str2/ :%norm jdd : 隔行删除 " 增加数字 (键入 ) :.,$g/^\d/exe "norm! \": 增加从当前行首到结尾的数字 :'a,'bg/\d\+/norm! ^A : 增加数字 " 保存全局命令的结果 (注意必须使用添加模式) 你需要使用 qaq 清空寄存器a. "save results to a register/paste buffer 存储结果到 寄存器/粘贴 到 a :g/fred/y A : 添加配备行到寄存器到 a :g/fred/y A | :let @*=@a : 放入复制缓冲区 :let @a=''|g/Barratt/y A |:let @*=@a :'a,'b g/^Error/ . w >> errors.txt " 复制每一行,然后在复制出来的每一行两侧加上一个 print '复制出来的内容' :g/./yank|put|-1s/'/"/g|s/.*/Print '&'/ " 用文件中的内容替换字符串,-d 表示删除“标记” :g/^MARK$/r tmp.ex | -d " display prettily :g//z#.5 : display with context :g//z#.5|echo "==========" : display beautifully " Combining g// with normal mode commands :g/|/norm 2f|r* : replace 2nd | with a star "send output of previous global command to a new window :nmap :redir @a:g//:redir END:new:put! a ---------------------------------------- " 全局命令和替换命令联姻 (强大的编辑能力) :'a,'bg/fred/s/joe/susan/gic : 可以使用反向引用来匹配 :g/fred/,/joe/s/fred/joe/gic : non-line based (ultra) ---------------------------------------- " 先找fred,然后找joe :/fred/;/joe/-2,/sid/+3s/sally/alley/gIC ---------------------------------------- " create a new file for each line of file eg 1.txt,2.txt,3,txt etc :g/^/exe ".w ".line(".").".txt" ---------------------------------------- " Absolutely essential ---------------------------------------- * # g* g# : 查找当前光标下的单词(单个单词) () (向前/向后) % : 匹配括号 {}[]() . : 重复上次操作 @: : 重复上次的命令 matchit.vim : 适%能匹配