vimのカーソル位置に外部コマンドの出力を追加する

vimのカーソル位置に外部コマンドの出力を追加する

を使用して:r !command、出力を次の行に追加します。

カーソルからのコマンド出力を同じ行に追加することは可能ですか?

答え1

挿入モードとコマンドライン モードの次のマッピングはどうでしょうか。

" i_CTRL-R_`        Insert the output of an external command.
" c_CTRL-R_`
function! s:QueryExternalCommand( newlineReplacement )
    call inputsave()
    let l:command = input('$ ', '', 'shellcmd')
    call inputrestore()
    return (empty(l:command) ?
    \   '' :
    \   substitute(substitute(system(l:command), '\n\+$', '', ''), '\n', a:newlineReplacement, 'g')
    \)
endfunction
inoremap <C-r>` <C-g>u<C-r>=<SID>QueryExternalCommand('\r')<CR>
cnoremap <C-r>` <C-r>=<SID>QueryExternalCommand('\\n')<CR>

関連情報