Regex (文件末尾的ext)之后仍将存在,但这很容易删除,并且可能由比我更了解VIM的人自动执行;-)很好,那个自我重复的宏是我思考了很长时间的东西。我完全忘记了nowrapscan。通过搜索使用自重复宏的非常平滑的方式。干杯如何从映射或函数中使用此答案?gg0q
Regex (文件末尾的ext)之后仍将存在,但这很容易删除,并且可能由比我更了解VIM的人自动执行;-)很好,那个自我重复的宏是我思考了很长时间的东西。我完全忘记了nowrapscan。通过搜索使用自重复宏的非常平滑的方式。干杯如何从映射或函数中使用此答案?gg0q,regex,vim,Regex,Vim,(文件末尾的ext)之后仍将存在,但这很容易删除,并且可能由比我更了解VIM的人自动执行;-)很好,那个自我重复的宏是我思考了很长时间的东西。我完全忘记了nowrapscan。通过搜索使用自重复宏的非常平滑的方式。干杯如何从映射或函数中使用此答案?gg0qac。。。当传递到“正常”时,该行的工作方式不同。似乎从未发送结束录制的q。类似地,使用递归宏删除前斜杠的更简单的normal命令也不起作用:normal QAF/x@aq使用后半部分作为映射会得到相同的结果。您可以停止碰撞,因为您使用的是函数
(文件末尾的ext)之后仍将存在,但这很容易删除,并且可能由比我更了解VIM的人自动执行;-)很好,那个自我重复的宏是我思考了很长时间的东西。我完全忘记了
nowrapscan
。通过搜索使用自重复宏的非常平滑的方式。干杯如何从映射或函数中使用此答案?gg0qac。。。当传递到“正常”时,该行的工作方式不同。似乎从未发送结束录制的q。类似地,使用递归宏删除前斜杠的更简单的normal命令也不起作用:normal QAF/x@aq
使用后半部分作为映射会得到相同的结果。您可以停止碰撞,因为您使用的是函数。这是通过在函数开始时用let old=@c
保存@c寄存器,并在函数结束时用let@c=old
恢复它来实现的。相关:在Vim设置中,这是一个很棒的宏。非常感谢。
grep --extended-regexp --only-matching --regexp="([0-9]{1,3}\.){3}[0-9]{1,3}"
"" Remove all text except what matches the current search result
"" The opposite of :%s///g (which clears all instances of the current search).
function! ClearAllButMatches()
let old = @c
let @c=""
%s//\=setreg('C', submatch(0), 'l')/g
%d _
put c
0d _
let @c = old
endfunction
"" Remove all text except what matches the current search result. Will put each
"" match on its own line. This is the opposite of :%s///g (which clears all
"" instances of the current search).
function! s:ClearAllButMatches() range
let is_whole_file = a:firstline == 1 && a:lastline == line('$')
let old_c = @c
let @c=""
exec a:firstline .','. a:lastline .'sub//\=setreg("C", submatch(0), "l")/g'
exec a:firstline .','. a:lastline .'delete _'
put! c
"" I actually want the above to replace the whole selection with c, but I'll
"" settle for removing the blank line that's left when deleting the file
"" contents.
if is_whole_file
$delete _
endif
let @c = old_c
endfunction
command! -range=% ClearAllButMatches <line1>,<line2>call s:ClearAllButMatches()
:%s/.\{-}\(<ip>\).*/\1/g
:1,$! grep --extended-regexp --only-matching --regexp="([0-9]{1,3}\.){3}[0-9]{1,3}"
:set nowrapscan
:let @a=""
gg0qac/\v(\d{1,3}\.){3}\d{1,3}<CR><CR><Esc>//e+1<CR>@aq@adG
:let @a=""
:%s//\=setreg('A', submatch(0), 'l')/g
:%d _
:pu a
:0d _
:let @a=""|%s//\=setreg('A', submatch(0), 'l')/g|%d _|pu a|0d _
:h :s\=
:h :let-@
:h submatch()
:h setreg()
:h :d
:h :p