0

Using :r !command, append the output to the next line.

Is it possible to append the command output from the cursor in the same line?

3
  • If you have xclip, you can type :r !command|xclip -i, then simply paste at the cursor. Note that all new-lines will be included in the pasted text.
    – AFH
    Jan 16, 2017 at 12:14
  • @AFH Nice workaround, but I am afraid that is not exactly what I was looking for. I would like to add that it works best when in insert mode before pasting.
    – Sathyam
    Jan 16, 2017 at 12:43
  • I would expect any added text to honour insert/overwrite mode, whatever mechanism might be used. You can reduce typing by using a script with a single letter (eg i) containing exec xclip -i, so that you need type only :r !command|i.
    – AFH
    Jan 16, 2017 at 12:53

1 Answer 1

1

How about the following mappings for insert and command-line mode:

" 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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.