Back to Blog
Jan 20, 2016 4 min read

Running Code Snippets in Vim Buffers

Vim Python

Running Code Snippets in Vim Buffers

I discovered this trick while trying to do some quick investigation in Vim, and not wanting to have to leave the editor, found a way to quickly replace Python code with its output.

What you do is, write the code inside a buffer, then select it in visual mode. Once it's selected, press : and you will get Vim's :'<,'> range. Then you can pipe it:

:'<,'>!python

This replaces the selected text with the output of the Python interpreter.

Thanks for reading!

I hope you found this technical dive useful. Feel free to connect with me if you have any questions or thoughts.

Connect with me
© 2026 Adam Lamers
Framework: Svelte_5
Runtime: Cloudflare