I want to execute the command "yiw:s/\<<C-r>"\>/<C-r>"/g<Left><Left>" by key sequence.
So I make a mapping
nnoremap <F7> yiw:s/\<<C-r>"\>/<C-r>"/g<Left><Left>
This mapping copy the word under cursor, then the string :s/\<">/"/g" (where " are substituted by the copied word) appears in the command line and the cursor in the command line is at the end of replacement statement.
I also want to save cursor position before this command and restore after.
function! SafeCommand(cmd)
let line = line('.')
let col = col('.')
// execute cmd here
call cursor( line, col )
endfunction
How to do that?
Fthen7, not<F7>. 2) if you want to do a:s/../../gyou need put<CR>there 3) even if there was a<CR>, your left left doesn't make sense either, because after substitution, your cursor would be at the beginning of that line. 4) I didn't understand what are you trying to do...replace the word under cursor with same word? can you explain it a bit in your question?Ctrl-Ocould bring you back to the old position. Also, you don't have to copy the current word, in command line<c-w> (:h <c-w>)will copy the word under cursor. do you want that function anyway?input(). I am not sure if passing a string as keysequence work in function, and stopping at command line and waiting for user finishing the cmd then pressing enter, then function continues.... at leastnormalorexecutedon't..