Skip to content

Instantly share code, notes, and snippets.

@miles-d
Last active July 30, 2020 11:07
Show Gist options
  • Save miles-d/2adb022dcc84890723035640f9187379 to your computer and use it in GitHub Desktop.
Save miles-d/2adb022dcc84890723035640f9187379 to your computer and use it in GitHub Desktop.
Insert result of external command in vim while in insert mode
" Prompt for input, execute, and trim newlines from the result.
function! ExternalCommandResult()
return system(input('Command: '))[:-2]
endfunction
" Create a mapping in insert mode.
inoremap <C-R>! <C-R>=ExternalCommandResult()<cr>
" Try it out with e.g. `date`: (be in insert mode) CTRL-R ! date ENTER
" If you like it, copy it to your .vimrc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment