使用find-exec编写Vim脚本

使用find-exec编写Vim脚本,vim,find,replace,Vim,Find,Replace,我有一个小Vim脚本,它执行多行搜索和替换: vim -c 's/^ *<hi a=\"26\">\nHello/<td height=\"26\">\r<\/table>\r<bla \/>' \ -c 'w!' -c 'q' test.html vim-c的/^*\nHello/\r\r'\ -哇-c'q'test.html 这很有效。但是,当我将其放在find-exec中,以便在目录中递归执行此操作时: find . -iname

我有一个小Vim脚本,它执行多行搜索和替换:

vim -c 's/^ *<hi a=\"26\">\nHello/<td height=\"26\">\r<\/table>\r<bla \/>' \
    -c 'w!' -c 'q' test.html
vim-c的/^*\nHello/\r\r'\
-哇-c'q'test.html
这很有效。但是,当我将其放在find-exec中,以便在目录中递归执行此操作时:

find . -iname 'test.html' -exec \
    vim -c 's/^ *<hi a=\"26\">\nHello/<td height=\"26\">\r<\/table>\r<bla \/>' \
    -c 'w!' -c 'q' \
{} \;
find-iname'test.html'-exec\
vim-c的/^*\nHello/\r\r'\
-哇-c'q'\
{} \;
test.html保持不变,Vim给出了以下错误:

Pattern not found:
  ^ *<hi a=\"26\">\nHello
in ./test.html
未找到模式: ^*\nHello 在./test.html中 这真的很奇怪,因为这是正确的正则表达式,我可以在Vim中手动搜索并获得成功


你能看到我的find语法有任何明显的错误吗?

你必须避开exec短语中的大括号(假设你没有看到,可能是论坛帖子吃了反斜杠)。它应该结束\{\}

你必须避开exec词组中的大括号(假设你没有,也许论坛发帖吃了后面的斜杠)。它应该结束\{\}

我想出来了!搜索模式需要%character:
vim-c“%s/switch/to/”
是正确的语法。

我找到了!搜索模式需要%character:
vim-c“%s/switch/to/”
是正确的语法。

当我做这样的事情时,我倾向于在vim中做

:vimgrep /^ *<hi a=\"26\">\nHello/ **/*
:vimgrep/^*\nHello/**/*
然后创建并执行递归宏:

qbq
qa (actually you don't press enter after this)
:silent! !p4 edit %  " check out the file
:e  " refresh the r/w status
:%s/^ *<hi a=\"26\">\nHello/<td height=\"26\">\r<\/table>\r<bla \/>
:w  " no need to force write if it's r/w
:cnf
q
qb@a@bq
@b
qbq
qa(实际上在此之后您不必按enter键)
:安静!p4编辑%“签出文件
:e“刷新r/w状态
:%s/^*\nHello/\r\r
:w“如果是r/w,则无需强制写入
:cnf
Q
qb@a@bq
@b

当我做这样的事情时,我倾向于在vim中做

:vimgrep /^ *<hi a=\"26\">\nHello/ **/*
:vimgrep/^*\nHello/**/*
然后创建并执行递归宏:

qbq
qa (actually you don't press enter after this)
:silent! !p4 edit %  " check out the file
:e  " refresh the r/w status
:%s/^ *<hi a=\"26\">\nHello/<td height=\"26\">\r<\/table>\r<bla \/>
:w  " no need to force write if it's r/w
:cnf
q
qb@a@bq
@b
qbq
qa(实际上在此之后您不必按enter键)
:silent!!p4 edit%“签出文件
:e“刷新r/w状态
:%s/^*\nHello/\r\r
:w“如果是r/w,则无需强制写入
:cnf
Q
qb@a@bq
@b

当您仅使用
-print
而不是
-exec
运行
find
时,它是否正确列出test.html?是的,当我仅使用-print时,它确实列出test.html。当我执行-exec时,它成功地使用Vim打开了文件。当您仅使用
-print
而不是
-exec
运行
find
时,它是否正确地列出test.html?是的,当我执行-print时,它确实列出test.html。当我执行-exec时,它成功地用Vim打开了文件。谢谢,我逃过了大括号。不过,我原来的问题依然存在:(谢谢,我躲过了大括号。不过,我原来的问题依然存在:(