_ is a linewise motion operator (:h linewise), its primary purpose is to move your cursor to <count> - 1 lines below your current position.
5_ will move your cursor 4 lines down
The motion to the beginning of the line is just a side effect of that move. So when you type d_, the delete operation is applied from the current line to 0 lines ...
Interesting question! 👍
Reading your attempts of code made me think of the order in which the operations are actually executed, which is:
The omap motion or text object is executed and selected.
The operator command (y, d, g~, etc.) is executed on that block of text.
It seems to me that some of your assumptions have the model backwards and assume that ...
That is indeed a novel and potentially time-saving feature!
The way to do this in plain Vim would be using :substitute for a range; the pattern can be easily set via * when the cursor is on top of it:
A mapping for the :s///g part that puts the cursor right into the replacement part can save many keystrokes here.
In order to ...
There's no way to change this behavior for all operators (short of mapping them all.)
But you can make your <F4> keep the cursor position (and window view) by saving and restoring it before and after it's used.
Note that since <F4> ends in an operator-pending g@ command, saving and restoring need to happen in different contexts, you should save ...
You can come up with something relatively simple, following and tinkering what vim has described in :h :map-operator:
As an example I came up with in about 15 minutes of experimenting:
nmap <silent> gi :set opfunc=InsertToTextObject<CR>g@
vmap <silent> gi :<C-U>call InsertToTextObject(visualmode(), 1)<CR>
nmap <silent> ...