VIM如何在文件中的不同位置插入shell命令的输出
我提出了一个perl脚本,它输出一个模板,用于根据我的C代码中的函数/结构定义来记录函数和结构 为了使用它,我从视觉上选择结构的定义,将其拖动并粘贴到原始定义的正上方,然后在这个粘贴的结构上调用脚本。它用该结构的文档替换它 现在有没有一种方法可以避免这种美国佬的做法?我正在寻找一种调用shell命令的方法,但是该命令的输出应该粘贴到文件中的其他地方,而不一定粘贴在它上面 瞧 :‘a,’b!perl~/bin/document.plVIM如何在文件中的不同位置插入shell命令的输出,vim,Vim,我提出了一个perl脚本,它输出一个模板,用于根据我的C代码中的函数/结构定义来记录函数和结构 为了使用它,我从视觉上选择结构的定义,将其拖动并粘贴到原始定义的正上方,然后在这个粘贴的结构上调用脚本。它用该结构的文档替换它 现在有没有一种方法可以避免这种美国佬的做法?我正在寻找一种调用shell命令的方法,但是该命令的输出应该粘贴到文件中的其他地方,而不一定粘贴在它上面 瞧 :‘a,’b!perl~/bin/document.pl 替换标记a和标记B之间的文本,我想在标记a上方添加documen
替换标记a和标记B之间的文本,我想在标记a上方添加document.pl的输出。一个可能的解决方案是修改perl脚本,使其在结尾也输出输入。然后,您将得到所需的结果。如果您使用zsh作为shell,您可以使用co-process:
'a,'b!coproc perl ~/bin/document.pl ; tee >&p | cat <&p
试试这样的方法:
function! MyFunc() range
" Preserve the register.
let old_reg = @a
exec a:firstline.','.a:lastline.'yank a'
" Change to do what you need with register a.
" Insert output before a:firstline
exec (a:firstline - 1).'read !your magic with '.@a
" Restore the register
let @a = old_reg
endfunction
" :2,5MyOwn will process lines from 2 to 5 and insert the output before line 2
command! -bar -range -nargs=? MyOwn <line1>,<line2>call MyFunc()
函数!MyFunc()范围
“保存登记册。
让old_reg=@a
执行官a:第一行.,'.a:最后一行.'yank a'
“更改以执行注册a所需的操作。
“在:第一行之前插入输出
执行官(a:firstline-1)。“读!你的魔法与”。@a
“恢复登记册
让@a=old\u reg
端功能
“:2,5MyOwn将处理从2到5的行,并在第2行之前插入输出
command!-bar-range-nargs=?MyOwn,调用MyFunc()
是的,我可以这样做,但我想保持脚本干净。我只能为VI创建另一个脚本。谢谢你的建议
'a,'byank a | new | 0put a | $d | execute "%!perl ~/bin/document.pl" | %d a | bw! | 'a-1put a
function! MyFunc() range
" Preserve the register.
let old_reg = @a
exec a:firstline.','.a:lastline.'yank a'
" Change to do what you need with register a.
" Insert output before a:firstline
exec (a:firstline - 1).'read !your magic with '.@a
" Restore the register
let @a = old_reg
endfunction
" :2,5MyOwn will process lines from 2 to 5 and insert the output before line 2
command! -bar -range -nargs=? MyOwn <line1>,<line2>call MyFunc()