Let's say I'm in a buffer like this, on line 4, I want to run line 1 to 2 and have the output in the same buffer on line 4 (where cursor is):
echo "more testing"
# and here I want the output from running lines 1 to 2
You were using
:w !... (
:help :w_c), but you probably want
gg - go to top Vj - select the two lines y - yank into a buffer 4gg - go to 4th line V - select it p - paste over it gv - reselect the pasted range :!sh<CR> - execute in shell and replace
or, trusting ex commands more,
:4d :1,2y :3pu :4,5!sh
!sh is in most cases equivalent to
! will call your default shell.