We can execute bash command from vim like this:

:! shuf -i1-123124 -n1

which generates random number in the given range. Is there a way to append the output to vim buffer?

3 Answers 3


:read ! shuf -i1-123124 -n1 Appending read before the command outputs it to the current buffer


You can use filtering through an external program. That's not the same as appending though. In the simplest case, you could replace the current line with the output of shuf.

For example, in normal mode, type !!, and then shuf -i1-123124 -n1. That will replace the current line with the output of shuf.

Alternatively, you could replace a specific line with the output of shuf with:

:123!shuf -i1-123124 -n1

Where 123 is the line you want to replace.

For more details and similar operations, see :help !!.

  • 1
    Instead of 123 you can also use . to refer to the current line or $ to refer to the last line. See :help range. Dec 31, 2016 at 3:43

:.! shuf -i1-123124 -n1 (with a dot) does the trick replacing the current line.

:r! shuf -i1-123124 -n1 creates a new line under cursor position.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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