Lets say I have a text file open in Vim, that looks like so
this is an inline insertion
and I want to add the word "test" between "inline" and "insertion".
I could just write it in, but this is a metaphoric example, so I'm going to :read !printf "test " with the cursor at column 18. Here's what I get:
this is an inline insertion
test
Here's what I want to get:
this is an inline test insertion
Is there any way to create a vim function or is there an existing command I can use to get this behavior? I know I could do the read, then do D k, then place the cursor, then P, but I was hoping to find a way to do this in one step, placing the cursor ahead of time.
EDIT
Thanks to @melpomene's answer, I have this function in my ~/.vimrc file now:
fu! InlineRead(command)
let colnum = col('.')
let line = getline('.')
call setline('.', strpart(line, 0, colnum) . system(a:command) . strpart(line, colnum))
endfu