Vim --- 从外部命令读取,在光标所在的位置插入

Vim --- Read from an External Command, Inserting Right Where the Cursor Is

:r !program 打开一个新行,插入我程序的输出,然后在其后插入一行。 我只是想在光标所在的位置插入输出,而不会造成额外的混乱。

我想我可以:

  1. 运行宏之前的一个

     mai^M^[`a 
    
     "Mark where I'm at, insert a line and go back
    
  2. 运行我的命令

    :r !echo -ne "line1\nline2\nline3"
    
  3. 运行 后宏(清理行)

    $mb:j!^M`a:j!^M`b 
    
    "Go to the end of inserted outpu
    "Mark it b
    "Join with the next line
    "Go to the first mark
    "Delete the inserted newline with :j!
    "Go to the second mark
    

如何将其组合成一个命令? 我希望能够做到:

:Readhere !echo -ne "line1\nline2\nline3"    

其中 :Readhere 将是我的自定义命令。

这可能会如您所愿。 (您不需要 !

command! -nargs=1 ReadHere exec 'normal! i' . system(<q-args>)

这将创建一个名为 ReadHere 的命令,它将所有内容都作为带引号的参数并将其直接传递给系统命令。然后我们使用 exec 在正常模式下插入所有内容。 (这可能不够稳健)


示例:起始缓冲区为

one two three

运行 :ReadHere echo -ne "line1\nline2\nline3" 光标在 w 上的位置产生

one tline1
line2
line3wo three